delay binding reassignment to after reference replacements - #751

This commit is contained in:
Sebastian McKenzie 2015-02-11 19:48:54 +11:00
parent 85d33536e0
commit 34ca1ac04f

View File

@ -155,11 +155,6 @@ Scope.prototype.rename = function (oldName, newName) {
var binding = info.identifier;
var scope = info.scope;
this.clearOwnBinding(oldName);
scope.bindings[newName] = info;
binding.name = newName;
scope.traverse(scope.block, {
enter: function (node, parent, scope) {
if (t.isReferencedIdentifier(node, parent) && node.name === oldName) {
@ -171,6 +166,11 @@ Scope.prototype.rename = function (oldName, newName) {
}
}
});
this.clearOwnBinding(oldName);
scope.bindings[newName] = info;
binding.name = newName;
};
Scope.prototype.inferType = function (node) {
@ -312,7 +312,7 @@ var programReferenceVisitor = {
state.addGlobal(node);
} else if (t.isLabeledStatement(node)) {
state.addGlobal(node);
} else if (t.isAssignmentExpression(node)) {
} else if (t.isAssignmentExpression(node) || t.isUpdateExpression(node)) {
scope.registerBindingReassignment(node);
}
}