Metro: Object Dot notation doesn't transpile when bundling for production

Created on 16 Jul 2017  路  3Comments  路  Source: facebook/metro

When bundling for production I'm getting an error when using dot notation over bracket notation whilst mutating an object:

Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got "StringLiteral"

Example:

    Platform['OS'] = platform.OS; // works
    Platform.OS = platform.OS; // doesn't work

This can be reproduced with the following steps:

> react-native init my-project
# ...
> cd my-project
> npm install react-primitives --save

# modify index.ios.js to: import { Text } from react-primitives;

node ./node_modules/react-native/local-cli/cli.js bundle --entry-file index.ios.js --platform ios --dev false --reset-cache --bundle-output /tmp/main.jsbundle --assets-dest /tmp/

I am tracking this issue on react-primitives here: https://github.com/lelandrichardson/react-primitives/issues/79

Most helpful comment

This seems like it would make for a good PR -- it's well-defined and fairly clear what the unit tests should look like. This is the relevant bit of code: https://github.com/facebook/metro-bundler/blob/3cbc2f3ec4ed4c92d2c7da5dc2a4e7a9de2ee3d5/packages/metro-bundler/src/JSTransformer/worker/inline.js#L118

All 3 comments

This seems like it would make for a good PR -- it's well-defined and fairly clear what the unit tests should look like. This is the relevant bit of code: https://github.com/facebook/metro-bundler/blob/3cbc2f3ec4ed4c92d2c7da5dc2a4e7a9de2ee3d5/packages/metro-bundler/src/JSTransformer/worker/inline.js#L118

I opened a PR for this. It's a pretty minimal change, but as far as I can tell it should cover the edge cases to solve this and the worked-around https://github.com/facebook/react-native/issues/7607#issuecomment-221425153

https://github.com/facebook/metro-bundler/pull/45

Thanks for the PR.

Was this page helpful?
0 / 5 - 0 ratings