Skip to content

Commit

Permalink
Fix helpers internal fns names conflict resolution (#16130)
Browse files Browse the repository at this point in the history
* Add test

* Fix it
  • Loading branch information
nicolo-ribaudo committed Nov 28, 2023
1 parent 4e6e3cf commit f8fcf77
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/babel-helpers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ function permuteHelperAST(

const toRename: Record<string, string> = {};
const bindings = new Set(localBindings || []);
if (id.type === "Identifier") bindings.add(id.name);
localBindingNames.forEach(name => {
let newName = name;
while (bindings.has(newName)) newName = "_" + newName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// We'll add the helper `set`. It needs to be renamed to `_set` to avoid
// conflicting with the variable name `set` in this file.
// However, the `set` helper declares a `_set` function itself, which will
// need to be renamed to avoid conflicts.

let set;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"minNodeVersion": "12.22.0",
"plugins": ["./plugin"]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function () {
return {
visitor: {
VariableDeclaration(path) {
this.addHelper("set");
},
},
};
}

0 comments on commit f8fcf77

Please sign in to comment.