index.js 1.4 KB

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