Sha256: 189db6f5b330f2019488b63e0c09ec6b63de6d70bb655eae1999d7a30eeaf882

Contents?: true

Size: 1.25 KB

Versions: 34

Compression:

Stored size: 1.25 KB

Contents

/**
 * Edge 16 & 17 do not infer function.name from variable assignment.
 * All other `function.name` behavior works fine, so we can skip most of @babel/transform-function-name.
 * @see https://kangax.github.io/compat-table/es6/#test-function_name_property_variables_(function)
 *
 * Note: contrary to various Github issues, Edge 16+ *does* correctly infer the name of Arrow Functions.
 * The variable declarator name inference issue only affects function expressions, so that's all we fix here.
 *
 * A Note on Minification: Terser undoes this transform *by default* unless `keep_fnames` is set to true.
 * There is by design - if Function.name is critical to your application, you must configure
 * your minifier to preserve function names.
 */

export default ({ types: t }) => ({
  name: "transform-edge-function-name",
  visitor: {
    FunctionExpression: {
      exit(path) {
        if (!path.node.id && t.isIdentifier(path.parent.id)) {
          const id = t.cloneNode(path.parent.id);
          const binding = path.scope.getBinding(id.name);
          // if the binding gets reassigned anywhere, rename it
          if (binding?.constantViolations.length) {
            path.scope.rename(id.name);
          }
          path.node.id = id;
        }
      },
    },
  },
});

Version data entries

34 entries across 33 versions & 6 rubygems

Version Path
immosquare-cleaner-0.1.62 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.61 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.60 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.59 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.58 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.57 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.56 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.55 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.54 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.53 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.52 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.51 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.50 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.49 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.48 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.47 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.46 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
immosquare-cleaner-0.1.45 node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
optimacms-0.1.61 spec/dummy/node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js
disco_app-0.16.1 test/dummy/node_modules/@babel/preset-modules/src/plugins/transform-edge-function-name/index.js