Debian Codegraph @

packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/src/index.ts

raw
1 import { declare } from "@babel/helper-plugin-utils";
2 import { shouldTransform } from "./util";
3
4 export default declare(api => {
5 api.assertVersion("^7.16.0");
6
7 return {
8 name: "plugin-bugfix-safari-id-destructuring-collision-in-function-expression",
9
10 visitor: {
11 FunctionExpression(path) {
12 const name = shouldTransform(path);
13 if (name) {
14 // Now we have (function a([a]) {})
15 const { scope } = path;
16 // invariant: path.node.id is always an Identifier here
17 const newParamName = scope.generateUid(name);
18 scope.rename(name, newParamName);
19 }
20 },
21 },
22 };
23 });