|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1012 bytes
|
| Line | |
|---|
| 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 |
|
|---|
| 7 | export default ({ types: t }) => {
|
|---|
| 8 | const isArrowParent = p =>
|
|---|
| 9 | p.parentKey === "params" &&
|
|---|
| 10 | p.parentPath &&
|
|---|
| 11 | t.isArrowFunctionExpression(p.parentPath);
|
|---|
| 12 |
|
|---|
| 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;
|
|---|
| 22 |
|
|---|
| 23 | // So, to ensure non-shorthand, rename the local identifier so it no longer matches:
|
|---|
| 24 | path.scope.rename(path.parent.key.name);
|
|---|
| 25 | }
|
|---|
| 26 | },
|
|---|
| 27 | },
|
|---|
| 28 | };
|
|---|
| 29 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.