source: trip-planner-front/node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/**
2 * Edge 16 & 17 do not infer function.name from variable assignment.
3 * All other `function.name` behavior works fine, so we can skip most of @babel/transform-function-name.
4 * @see https://kangax.github.io/compat-table/es6/#test-function_name_property_variables_(function)
5 *
6 * Note: contrary to various Github issues, Edge 16+ *does* correctly infer the name of Arrow Functions.
7 * The variable declarator name inference issue only affects function expressions, so that's all we fix here.
8 *
9 * A Note on Minification: Terser undoes this transform *by default* unless `keep_fnames` is set to true.
10 * There is by design - if Function.name is critical to your application, you must configure
11 * your minifier to preserve function names.
12 */
13
14export default ({ types: t }) => ({
15 name: "transform-edge-function-name",
16 visitor: {
17 FunctionExpression: {
18 exit(path) {
19 if (!path.node.id && t.isIdentifier(path.parent.id)) {
20 const id = t.cloneNode(path.parent.id);
21 const binding = path.scope.getBinding(id.name);
22 // if the binding gets reassigned anywhere, rename it
23 if (binding?.constantViolations.length) {
24 path.scope.rename(id.name);
25 }
26 path.node.id = id;
27 }
28 },
29 },
30 },
31});
Note: See TracBrowser for help on using the repository browser.