index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. /**
  5. * Converts destructured parameters with default values to non-shorthand syntax.
  6. * This fixes the only arguments-related bug in ES Modules-supporting browsers (Edge 16 & 17).
  7. * Use this plugin instead of @babel/plugin-transform-parameters when targeting ES Modules.
  8. */
  9. var _default = ({
  10. types: t
  11. }) => {
  12. const isArrowParent = p => p.parentKey === "params" && p.parentPath && t.isArrowFunctionExpression(p.parentPath);
  13. return {
  14. name: "transform-edge-default-parameters",
  15. visitor: {
  16. AssignmentPattern(path) {
  17. const arrowArgParent = path.find(isArrowParent);
  18. if (arrowArgParent && path.parent.shorthand) {
  19. // In Babel 7+, there is no way to force non-shorthand properties.
  20. path.parent.shorthand = false;
  21. (path.parent.extra || {}).shorthand = false; // So, to ensure non-shorthand, rename the local identifier so it no longer matches:
  22. path.scope.rename(path.parent.key.name);
  23. }
  24. }
  25. }
  26. };
  27. };
  28. exports.default = _default;
  29. module.exports = exports.default;