Enable JSX source plugin in DEV and integrate it with React DevTools

Summary:
The `env` option has been broken in Babel for a while (https://github.com/babel/babel/issues/4539), and will be deprecated (https://github.com/babel/babel/issues/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 https://github.com/facebook/react-native/pull/13893

Reviewed By: gaearon

Differential Revision: D5035892

Pulled By: davidaurelio

fbshipit-source-id: 19ffeb867d7ed5928e9de05dcec9ba85bf961dd5
This commit is contained in:
Dan Abramov 2017-05-12 08:43:02 -07:00 коммит произвёл Facebook Github Bot
Родитель 6e2c07534e
Коммит 7210a060e6
3 изменённых файлов: 12 добавлений и 8 удалений

Просмотреть файл

@ -10,7 +10,7 @@
var resolvePlugins = require('../lib/resolvePlugins');
module.exports = {
var preset = {
comments: false,
compact: true,
plugins: resolvePlugins([
@ -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;

Просмотреть файл

@ -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",

Просмотреть файл

@ -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",