From 34ca1ac04ffad0b47cc65b2c179f8bf68a95be9d Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Wed, 11 Feb 2015 19:48:54 +1100 Subject: [PATCH] delay binding reassignment to after reference replacements - #751 --- lib/6to5/traversal/scope.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/6to5/traversal/scope.js b/lib/6to5/traversal/scope.js index c9710696a0..47df9504f7 100644 --- a/lib/6to5/traversal/scope.js +++ b/lib/6to5/traversal/scope.js @@ -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); } }