Urara-Blog/node_modules/.pnpm-store/v3/files/a0/2ea5e5fa85ecbb3b2b67dca5c98d7573dfbe98f497be145a70ff62009cadeae5fde0b58668925287da86d874a1ea0bd8b17e7dfb9457be4cf984f09e05b0f0
2022-08-14 01:14:53 +08:00

29 lines
1,012 B
Text

/**
* Converts destructured parameters with default values to non-shorthand syntax.
* This fixes the only arguments-related bug in ES Modules-supporting browsers (Edge 16 & 17).
* Use this plugin instead of @babel/plugin-transform-parameters when targeting ES Modules.
*/
export default ({ types: t }) => {
const isArrowParent = p =>
p.parentKey === "params" &&
p.parentPath &&
t.isArrowFunctionExpression(p.parentPath);
return {
name: "transform-edge-default-parameters",
visitor: {
AssignmentPattern(path) {
const arrowArgParent = path.find(isArrowParent);
if (arrowArgParent && path.parent.shorthand) {
// In Babel 7+, there is no way to force non-shorthand properties.
path.parent.shorthand = false;
(path.parent.extra || {}).shorthand = false;
// So, to ensure non-shorthand, rename the local identifier so it no longer matches:
path.scope.rename(path.parent.key.name);
}
},
},
};
};