Skip to content

Commit

Permalink
fix renaming variables in the same scope
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzoferre committed Sep 18, 2024
1 parent 877d53c commit 9cc4900
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/techniques/statics/rename-variable-same-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ export default function () {
return {
name: "rename-variable-same-scope",
visitor: {
VariableDeclarator: {
Program: {
enter(path) {
const { node, scope } = path;
const { id } = node;
const { name } = id;
const { parent } = scope;
if (!parent) return;
for (const binding in parent.bindings) {
if (binding === name) {
const newName = scope.generateUidIdentifier(name);
scope.rename(name, newName.name);
}
}
path.traverse({
VariableDeclarator(innerPath) {
const { node, scope } = innerPath;
const { id } = node;
const { name } = id;
const { parent } = scope;
if (!parent) return;
for (const binding in parent.bindings) {
if (binding === name) {
const newName = scope.generateUidIdentifier(name);
scope.rename(name, newName.name);
}
}
},
});
},
},
},
Expand Down

0 comments on commit 9cc4900

Please sign in to comment.