Skip to content

Commit

Permalink
Enable JSX source plugin in DEV and integrate it with React DevTools
Browse files Browse the repository at this point in the history
Summary:
The `env` option has been broken in Babel for a while (babel/babel#4539), and will be deprecated (babel/babel#5276).

I am changing this code to the way Babel < 6.10 interpreted the `env` option. This should fix the `__source` JSX transform which was applied in DEV in the past, but stopped getting applied because of the Babel bug.

I also changed the `filename` passed by Babel to be relative (currently, to `fbsource` but open to other options). This way DEV builds are still reproducible.

This still needs some help from davidaurelio to make the root location more foolproof. I'd also appreciate zertosh taking a look in case there's a better way to "anchor" the relative path. All I need is to for `react-third-party/react-devtools/react-devtools` and `babelTransformer.js` to agree on what the relative path base is.

Closes facebook#13893

Reviewed By: gaearon

Differential Revision: D5035892

Pulled By: davidaurelio

fbshipit-source-id: 19ffeb867d7ed5928e9de05dcec9ba85bf961dd5
  • Loading branch information
gaearon authored and facebook-github-bot committed May 12, 2017
1 parent 6e2c075 commit 7210a06
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions babel-preset/configs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

var resolvePlugins = require('../lib/resolvePlugins');

module.exports = {
var preset = {
comments: false,
compact: true,
plugins: resolvePlugins([
Expand Down Expand Up @@ -40,11 +40,15 @@ module.exports = {
['transform-es2015-for-of', { loose: true }],
require('../transforms/transform-symbol-member'),
]),
env: {
development: {
plugins: resolvePlugins(['transform-react-jsx-source']),
},
},
retainLines: true,
sourceMaps: false,
};

var env = process.env.BABEL_ENV || process.env.NODE_ENV;
if (!env || env === 'development') {
preset.plugins = preset.plugins.concat(
resolvePlugins(['transform-react-jsx-source'])
);
}

module.exports = preset;
2 changes: 1 addition & 1 deletion babel-preset/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-preset-react-native",
"version": "1.9.0",
"version": "1.9.2",
"description": "Babel preset for React Native applications",
"main": "index.js",
"repository": "https://github.com/facebook/react-native/tree/master/babel-preset",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"babel-polyfill": "^6.20.0",
"babel-preset-es2015-node": "^6.1.1",
"babel-preset-fbjs": "^2.1.2",
"babel-preset-react-native": "^1.9.1",
"babel-preset-react-native": "^1.9.2",
"babel-register": "^6.24.1",
"babel-runtime": "^6.23.0",
"babel-traverse": "^6.24.1",
Expand Down

0 comments on commit 7210a06

Please sign in to comment.