Fix shadow variables reassignment for block scoping in loops. (#6814)
This commit is contained in:
committed by
Mateusz Burzyński
parent
84fe8e4181
commit
056a995dd8
@@ -247,6 +247,8 @@ const continuationVisitor = {
|
||||
}
|
||||
state.reassignments[name] = true;
|
||||
}
|
||||
} else if (path.isReturnStatement()) {
|
||||
state.returnStatements.push(path);
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -585,6 +587,7 @@ class BlockScoping {
|
||||
addContinuations(fn) {
|
||||
const state = {
|
||||
reassignments: {},
|
||||
returnStatements: [],
|
||||
outsideReferences: this.outsideLetReferences,
|
||||
};
|
||||
|
||||
@@ -599,6 +602,12 @@ class BlockScoping {
|
||||
|
||||
this.scope.rename(param.name, newParam.name, fn);
|
||||
|
||||
state.returnStatements.forEach(returnStatement => {
|
||||
returnStatement.insertBefore(
|
||||
t.expressionStatement(t.assignmentExpression("=", param, newParam)),
|
||||
);
|
||||
});
|
||||
|
||||
// assign outer reference as it's been modified internally and needs to be retained
|
||||
fn.body.body.push(
|
||||
t.expressionStatement(t.assignmentExpression("=", param, newParam)),
|
||||
|
||||
Reference in New Issue
Block a user