{"version":3,"file":"index.js","sources":["../src/util.ts","../src/index.ts"],"sourcesContent":["import type { FunctionExpression } from \"@babel/types\";\nimport type { NodePath } from \"@babel/traverse\";\n\n/**\n * Check whether a function expression can be affected by\n * https://bugs.webkit.org/show_bug.cgi?id=220517\n * @param path The function expression NodePath\n * @returns the name of function id if it should be transformed, otherwise returns false\n */\nexport function shouldTransform(\n path: NodePath,\n): string | false {\n const { node } = path;\n const functionId = node.id;\n if (!functionId) return false;\n\n const name = functionId.name;\n // On collision, `getOwnBinding` returns the param binding\n // with the id binding be registered as constant violation\n const paramNameBinding = path.scope.getOwnBinding(name);\n if (paramNameBinding === undefined) {\n // Case 1: the function id is injected by babel-helper-name-function, which\n // assigns `NOT_LOCAL_BINDING` to the `functionId` and thus not registering id\n // in scope tracking\n // Case 2: the function id is injected by a third party plugin which does not update the\n // scope info\n return false;\n }\n if (paramNameBinding.kind !== \"param\") {\n // the function id does not reproduce in params\n return false;\n }\n\n if (paramNameBinding.identifier === paramNameBinding.path.node) {\n // the param binding is a simple parameter\n // e.g. (function a(a) {})\n return false;\n }\n\n return name;\n}\n","import { declare } from \"@babel/helper-plugin-utils\";\nimport { shouldTransform } from \"./util.ts\";\n\nexport default declare(api => {\n api.assertVersion(\"^7.16.0\");\n\n return {\n name: \"plugin-bugfix-safari-id-destructuring-collision-in-function-expression\",\n\n visitor: {\n FunctionExpression(path) {\n const name = shouldTransform(path);\n if (name) {\n // Now we have (function a([a]) {})\n const { scope } = path;\n // invariant: path.node.id is always an Identifier here\n const newParamName = scope.generateUid(name);\n scope.rename(name, newParamName);\n }\n },\n },\n };\n});\n"],"names":["shouldTransform","path","node","functionId","id","name","paramNameBinding","scope","getOwnBinding","undefined","kind","identifier","declare","api","assertVersion","visitor","FunctionExpression","newParamName","generateUid","rename"],"mappings":";;;;;;AASO,SAASA,eAAeA,CAC7BC,IAAkC,EAClB;EAChB,MAAM;AAAEC,IAAAA,IAAAA;AAAK,GAAC,GAAGD,IAAI,CAAA;AACrB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