fix renaming of assignment expressions to fix pattern renaming in the es6.blockScoping transformer - fixes #1576

This commit is contained in:
Sebastian McKenzie
2015-05-20 10:34:50 +01:00
parent de1e965fec
commit af4feb4d88
4 changed files with 40 additions and 5 deletions

View File

@@ -84,8 +84,6 @@ export function BlockStatement(block, parent, scope, file) {
export { BlockStatement as Program };
function replace(node, parent, scope, remaps) {
if (!t.isReferencedIdentifier(node, parent)) return;
var remap = remaps[node.name];
if (!remap) return;
@@ -100,11 +98,21 @@ function replace(node, parent, scope, remaps) {
}
var replaceVisitor = {
enter: replace
ReferencedIdentifier: replace,
AssignmentExpression(node, parent, scope, remaps) {
var ids = this.getBindingIdentifiers();
for (var name in ids) {
replace(ids[name], node, scope, remaps);
}
},
};
function traverseReplace(node, parent, scope, remaps) {
replace(node, parent, scope, remaps);
if (t.isIdentifier(node)) {
replace(node, parent, scope, remaps);
}
scope.traverse(node, replaceVisitor, remaps);
}

View File

@@ -260,10 +260,15 @@ export default class TraversalPath {
do {
var container = path.container;
if (path.isFunction()) {
return false;
}
if (Array.isArray(container) && path.key !== container.length - 1) {
return false;
}
} while (path = path.parentPath && !path.isProgram());
} while ((path = path.parentPath) && !path.isProgram());
return true;
}