2ea5e5fa85ecbb3b2b67dca5c98d7573dfbe98f497be145a70ff62009cadeae5fde0b58668925287da86d874a1ea0bd8b17e7dfb9457be4cf984f09e05b0f0 1012 B

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