4Catalyzer / babel-plugin-dev-expression

A mirror of Facebook's dev-expression Babel plugin
MIT License
184 stars 6 forks source link

Doesn't work with React Native #4

Open cooperka opened 7 years ago

cooperka commented 7 years ago

I got a very similar issue to https://github.com/4Catalyzer/babel-plugin-dev-expression/issues/2 using React Native v0.43. After some testing, it turns out this plugin doesn't work at all with React Native :(

Property property of MemberExpression expected node to be of a type ["Identifier"] but instead got "BinaryExpression"

Working demo project: https://github.com/cooperka/DemoDevExpression

Full stack:

error: bundling: TypeError: /Users/me/dev/apps/my-app/node_modules/react-native/packager/src/Resolver/polyfills/prelude_dev.js: Property property of MemberExpression expected node to be of a type ["Identifier"] but instead got "BinaryExpression"
    at validate (/Users/me/dev/apps/my-app/node_modules/babel-types/lib/definitions/index.js:109:13)
    at Object.validate (/Users/me/dev/apps/my-app/node_modules/babel-types/lib/definitions/core.js:412:50)
    at Object.validate (/Users/me/dev/apps/my-app/node_modules/babel-types/lib/index.js:505:9)
    at NodePath._replaceWith (/Users/me/dev/apps/my-app/node_modules/babel-traverse/lib/path/replacement.js:176:7)
    at NodePath.replaceWith (/Users/me/dev/apps/my-app/node_modules/babel-traverse/lib/path/replacement.js:160:8)
    at PluginPass.enter (/Users/me/dev/apps/my-app/node_modules/babel-plugin-dev-expression/dev-expression.js:41:18)
    at newFn (/Users/me/dev/apps/my-app/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (/Users/me/dev/apps/my-app/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/me/dev/apps/my-app/node_modules/babel-traverse/lib/path/context.js:48:17)
TransformError: /Users/me/dev/apps/my-app/node_modules/react-native/packager/src/Resolver/polyfills/prelude_dev.js: /Users/me/dev/apps/my-app/node_modules/react-native/packager/src/Resolver/polyfills/prelude_dev.js: Property property of MemberExpression expected node to be of a type ["Identifier"] but instead got "BinaryExpression"
Bundling `index.ios.js`  100.0% (1991/1991), failed.

.babelrc:

{
  "presets": ["react-native"],
  "plugins": ["dev-expression"]
}

Any idea what's going on or how to fix it?

taion commented 6 years ago

Hmm, I think this is picking up on object keys that are __DEV__.

jquense commented 6 years ago

it does do that, i've had to do { '__DEV__': true } to trick it...

taion commented 6 years ago

yeahhhhh what do you think are the odds that they'll accept a PR to fix this upstream? or should we make this an actual fork instead of a copy/paste?