Merge pull request #4940 from appden/fix-react-constant-elements

Fix React constant element bugs
This commit is contained in:
Henry Zhu
2016-12-16 15:29:05 -05:00
committed by GitHub
7 changed files with 86 additions and 11 deletions

View File

@@ -305,14 +305,14 @@ class BlockScoping {
this.remap();
}
this.updateScopeInfo();
this.updateScopeInfo(needsClosure);
if (this.loopLabel && !t.isLabeledStatement(this.loopParent)) {
return t.labeledStatement(this.loopLabel, this.loop);
}
}
updateScopeInfo() {
updateScopeInfo(wrappedInClosure) {
let scope = this.scope;
let parentScope = scope.getFunctionParent();
let letRefs = this.letReferences;
@@ -323,7 +323,12 @@ class BlockScoping {
if (!binding) continue;
if (binding.kind === "let" || binding.kind === "const") {
binding.kind = "var";
scope.moveBindingTo(ref.name, parentScope);
if (wrappedInClosure) {
scope.removeBinding(ref.name);
} else {
scope.moveBindingTo(ref.name, parentScope);
}
}
}
}