index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var helperPluginUtils = require('@babel/helper-plugin-utils');
  4. function shouldTransform(path) {
  5. const {
  6. node
  7. } = path;
  8. const functionId = node.id;
  9. if (!functionId) return false;
  10. const name = functionId.name;
  11. const paramNameBinding = path.scope.getOwnBinding(name);
  12. if (paramNameBinding === undefined) {
  13. return false;
  14. }
  15. if (paramNameBinding.kind !== "param") {
  16. return false;
  17. }
  18. if (paramNameBinding.identifier === paramNameBinding.path.node) {
  19. return false;
  20. }
  21. return name;
  22. }
  23. var index = helperPluginUtils.declare(api => {
  24. api.assertVersion("^7.16.0");
  25. return {
  26. name: "plugin-bugfix-safari-id-destructuring-collision-in-function-expression",
  27. visitor: {
  28. FunctionExpression(path) {
  29. const name = shouldTransform(path);
  30. if (name) {
  31. const {
  32. scope
  33. } = path;
  34. const newParamName = scope.generateUid(name);
  35. scope.rename(name, newParamName);
  36. }
  37. }
  38. }
  39. };
  40. });
  41. exports["default"] = index;
  42. //# sourceMappingURL=index.js.map