-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Enable strict mode for transform-es2015-modules-commonjs #5796
Conversation
By analyzing the blame information on this pull request, we identified @skevy to be a potential reviewer. |
cc @martinbigio |
@janicduplessis updated the pull request. |
1 similar comment
@janicduplessis updated the pull request. |
Would be awesome to get it merged. |
Looks good to me, just need someone at Facebook to make the changes to their .babelrc's as necessary. |
@martinbigio this is related to #6403 that I asked you to check. |
I retested this recently and it need #6255 to be merged to work properly or keep the allowTopLevelThis. |
@janicduplessis updated the pull request. |
@janicduplessis does this need to be rebased? |
@janicduplessis updated the pull request. |
4118dec
to
cdba9d3
Compare
@janicduplessis updated the pull request. |
cdba9d3
to
df9efe9
Compare
@janicduplessis updated the pull request. |
I removed the allowTopLevelThis since it's already addressed in #6255 and rebased on master. All tests should pass now. |
@facebook-github-bot shipit |
Thanks for importing. If you are an FB employee go to Phabricator to review. |
@janicduplessis have you tested this with a manual babel transform? Our apps internally use babel imperatively:
If I do
before calling transform I still get "use strict" injected automatically |
No I haven't tested that. Did you clear the packager cache to make sure the transforms are all run again? |
Tested this and it worked:
It prints |
Thanks a lot, mate. |
Good luck :) |
Summary:Since facebook#5422 react-native works with strict mode modules but the transform was not updated since Facebook has some non strict mode compatible internal modules. Now that facebook#5214 has landed and it is easy to change the babel config I think we should enable it by default to make es2015 modules spec compliant. Someone at Facebook will have to make the internal changes necessary to disable strict mode modules for their projects that use non strict mode compatible modules by including a .babelrc file with ``` json { "presets": [ "react-native" ], "plugins": [ ["transform-es2015-modules-commonjs", { "strict": false, "allowTopLevelThis": true }] ] } ``` before merging this. We might also want to mention this in the breaking change section for the next release. Closes facebook#5796 Differential Revision: D3075802 fb-gh-sync-id: e807b67401107e1e944db38453e254025ce0a6c7 shipit-source-id: e807b67401107e1e944db38453e254025ce0a6c7
Ok, we should probably revert this. Not sure what changed in babel but changing a plugin option by defining it a second time doesn't work anymore. Since we transform all the code in node_modules by default there are a lot of issues with libraries that don't support strict mode. Right now the only way to disable it is to not use babel-preset-react-native and define all the transforms manually so it is not very convenient. Let's wait until there is a supported way to pass options to presets in babel so disabling strict mode is easy. Also I know there was already some discussion about that but shipping react-native and libraries already compiled would help a lot here. cc @bestander |
Sounds good to me. On Sunday, 27 March 2016, Janic Duplessis notifications@github.com wrote:
|
There's always a risk of breaking third party code since we're transpiling things under |
Makes sense actually. On Sunday, 27 March 2016, Satyajit Sahoo notifications@github.com wrote:
|
@bestander Yeah. And keep the original files as *.flow files, so flow works for consumers. |
I know David Aurelio wanted to get rid of haste code with transpiling A discussion in Core Contributors group maybe? On Sunday, 27 March 2016, Satyajit Sahoo notifications@github.com wrote:
|
@bestander Yeah, will post in the group. :) |
Summary:See discussion here #5796 (comment) **Test plan (required)** Change the babel-preset-react-native dependency to `"babel-preset-react-native": "file:./babel-preset",` so it uses the local babel-preset instead of the one from npm. ``` ./packager/packager.sh --reset-cache ``` open `http://localhost:8081/Examples/UIExplorer/UIExplorerApp.android.bundle?platform=android&dev=true&hot=false&minify=false` and there should not be any added 'strict mode'. Closes #6686 Reviewed By: mkonicek Differential Revision: D3103122 Pulled By: bestander fb-gh-sync-id: 85658ee01bb73f13dacb2b6a48ab121324c13118 fbshipit-source-id: 85658ee01bb73f13dacb2b6a48ab121324c13118
Summary:See discussion here facebook#5796 (comment) **Test plan (required)** Change the babel-preset-react-native dependency to `"babel-preset-react-native": "file:./babel-preset",` so it uses the local babel-preset instead of the one from npm. ``` ./packager/packager.sh --reset-cache ``` open `http://localhost:8081/Examples/UIExplorer/UIExplorerApp.android.bundle?platform=android&dev=true&hot=false&minify=false` and there should not be any added 'strict mode'. Closes facebook#6686 Reviewed By: mkonicek Differential Revision: D3103122 Pulled By: bestander fb-gh-sync-id: 85658ee01bb73f13dacb2b6a48ab121324c13118 fbshipit-source-id: 85658ee01bb73f13dacb2b6a48ab121324c13118
Since #5422 react-native works with strict mode modules but the transform was not updated since Facebook has some non strict mode compatible internal modules. Now that #5214 has landed and it is easy to change the babel config I think we should enable it by default to make es2015 modules spec compliant.
Someone at Facebook will have to make the internal changes necessary to disable strict mode modules for their projects that use non strict mode compatible modules by including a .babelrc file with
before merging this.
We might also want to mention this in the breaking change section for the next release.