Skip to content

Commit

Permalink
Add transform-react-jsx-source to react-native preset
Browse files Browse the repository at this point in the history
Summary:
Putting this up as request for comments.

The PR adds [transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) to the list of plugins that come by default with the `react-native` preset. It will enable the use of a bunch of really cool tooling around JSX, however those are generally useful only in development mode. Is changing `react-native` preset the right thing to do in this case? Is there a way to enable this transform only in DEV? Should I add this somewhere else?
Closes facebook#6351

Differential Revision: D3302906

Pulled By: frantic

fbshipit-source-id: 012d3a4142168f9f90d30d1686115d4dc3996eb9
  • Loading branch information
frantic authored and Facebook Github Bot 0 committed May 18, 2016
1 parent 18e1b1f commit 858643d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
5 changes: 5 additions & 0 deletions babel-preset/configs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ 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,
};
3 changes: 2 additions & 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.7.0",
"version": "1.8.0",
"description": "Babel preset for React Native applications",
"main": "index.js",
"repository": "https://github.com/facebook/react-native/tree/master/babel-preset",
Expand Down Expand Up @@ -39,6 +39,7 @@
"babel-plugin-transform-object-assign": "^6.5.0",
"babel-plugin-transform-object-rest-spread": "^6.5.0",
"babel-plugin-transform-react-display-name": "^6.5.0",
"babel-plugin-transform-react-jsx-source": "^6.5.0",
"babel-plugin-transform-react-jsx": "^6.5.0",
"babel-plugin-transform-regenerator": "^6.5.0",
"react-transform-hmr": "^1.0.4"
Expand Down
1 change: 1 addition & 0 deletions babel-preset/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = {
'babel-plugin-transform-object-assign': require('babel-plugin-transform-object-assign'),
'babel-plugin-transform-object-rest-spread': require('babel-plugin-transform-object-rest-spread'),
'babel-plugin-transform-react-display-name': require('babel-plugin-transform-react-display-name'),
'babel-plugin-transform-react-jsx-source': require('babel-plugin-transform-react-jsx-source'),
'babel-plugin-transform-react-jsx': require('babel-plugin-transform-react-jsx'),
'babel-plugin-transform-regenerator': require('babel-plugin-transform-regenerator'),
'babel-plugin-transform-es2015-for-of': require('babel-plugin-transform-es2015-for-of'),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"babel-core": "^6.6.4",
"babel-plugin-external-helpers": "^6.5.0",
"babel-polyfill": "^6.6.1",
"babel-preset-react-native": "^1.7.0",
"babel-preset-react-native": "^1.8.0",
"babel-register": "^6.6.0",
"babel-types": "^6.6.4",
"babylon": "^6.6.4",
Expand Down
25 changes: 16 additions & 9 deletions packager/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,22 @@ function buildBabelConfig(filename, options) {
function transform(src, filename, options) {
options = options || {};

const babelConfig = buildBabelConfig(filename, options);
const result = babel.transform(src, babelConfig);

return {
ast: result.ast,
code: result.code,
map: result.map,
filename: filename,
};
const OLD_BABEL_ENV = process.env.BABEL_ENV;
process.env.BABEL_ENV = options.dev ? 'development' : 'production';

try {
const babelConfig = buildBabelConfig(filename, options);
const result = babel.transform(src, babelConfig);

return {
ast: result.ast,
code: result.code,
map: result.map,
filename: filename,
};
} finally {
process.env.BABEL_ENV = OLD_BABEL_ENV;
}
}

module.exports = function(data, callback) {
Expand Down

0 comments on commit 858643d

Please sign in to comment.