Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[babel-plugin] removeDefaultMessage incompatible w/ idInterpolationPattern #2305

Closed
IcanDivideBy0 opened this issue Nov 11, 2020 · 1 comment · Fixed by #2306
Closed

[babel-plugin] removeDefaultMessage incompatible w/ idInterpolationPattern #2305

IcanDivideBy0 opened this issue Nov 11, 2020 · 1 comment · Fixed by #2306
Labels

Comments

@IcanDivideBy0
Copy link
Contributor

IcanDivideBy0 commented Nov 11, 2020

Which package?
babel-plugin-react-intl

Describe the bug
When using removeDefaultMessage, babel compilation crashes:

SyntaxError: xxx.js: NodePath has been removed so is read-only.
    at File.buildCodeFrameError (xxx/node_modules/@babel/core/lib/transformation/file/file.js:250:12)
    at NodePath.buildCodeFrameError (xxx/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/index.js:163:21)
    at NodePath._assertUnremoved (xxx/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/removal.js:68:16)
    at NodePath.insertBefore (xxx/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/modification.js:32:8)
    at PluginPass.JSXOpeningElement (xxx/node_modules/babel-plugin-react-intl/index.js:331:52)
    at newFn (xxx/node_modules/@babel/core/node_modules/@babel/traverse/lib/visitors.js:175:21)
    at NodePath._call (xxx/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:55:20)
    at NodePath.call (xxx/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:42:17)
    at NodePath.visit (xxx/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:92:31)
    at TraversalContext.visitQueue (xxx/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:116:16) {
  code: 'BABEL_TRANSFORM_ERROR'
}

I suspect that defaultMessageAttr is removed from AST here, then possibly used here

To Reproduce

Steps to reproduce the behavior:

  1. use the following babel config:
{
  "plugins": [
    [
      "react-intl",
      {
        "idInterpolationPattern": "[sha512:contenthash:base64:6]",
        "removeDefaultMessage": true
      }
    ],
  ]
}
  1. define some message w/ an id:
    [edit]: without an id
const messages = defineMessages({
  foo: {
    defaultMessage: "hello",
  },
});

Expected behavior
babel should not crash

Additional context
@babel/core@7.12.3
babel-plugin-react-intl@8.2.13

@IcanDivideBy0
Copy link
Contributor Author

IcanDivideBy0 commented Nov 11, 2020

The problem really seem to come from this line

defaultMessageAttr has been removed from the AST so we can't .insertBefore it !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant