From 5caa05dc5f29db516f3bb6ff01c37e3dc20dd313 Mon Sep 17 00:00:00 2001 From: Fabrizio Castellarin Date: Tue, 6 Dec 2016 14:50:50 +0100 Subject: [PATCH] [babel-preset-react-app] Temporary fix missing babel plugins (#1177) * temporary fix missing babel plugins * Add an issue link --- packages/babel-preset-react-app/index.js | 62 ++++++++++++-------- packages/babel-preset-react-app/package.json | 3 + 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/packages/babel-preset-react-app/index.js b/packages/babel-preset-react-app/index.js index 1f7ec0f8e0e..0188b9484c1 100644 --- a/packages/babel-preset-react-app/index.js +++ b/packages/babel-preset-react-app/index.js @@ -11,32 +11,32 @@ var path = require('path'); const plugins = [ - // class { handleClick = () => { } } - require.resolve('babel-plugin-transform-class-properties'), - // The following two plugins use Object.assign directly, instead of Babel's - // extends helper. Note that this assumes `Object.assign` is available. - // { ...todo, completed: true } - [require.resolve('babel-plugin-transform-object-rest-spread'), { - useBuiltIns: true - }], - // Transforms JSX - [require.resolve('babel-plugin-transform-react-jsx'), { - useBuiltIns: true - }], - // function* () { yield 42; yield 43; } - [require.resolve('babel-plugin-transform-regenerator'), { - // Async functions are converted to generators by babel-preset-latest - async: false - }], - // Polyfills the runtime needed for async/await and generators - [require.resolve('babel-plugin-transform-runtime'), { - helpers: false, - polyfill: false, - regenerator: true, - // Resolve the Babel runtime relative to the config. - moduleName: path.dirname(require.resolve('babel-runtime/package')) - }] - ]; + // class { handleClick = () => { } } + require.resolve('babel-plugin-transform-class-properties'), + // The following two plugins use Object.assign directly, instead of Babel's + // extends helper. Note that this assumes `Object.assign` is available. + // { ...todo, completed: true } + [require.resolve('babel-plugin-transform-object-rest-spread'), { + useBuiltIns: true + }], + // Transforms JSX + [require.resolve('babel-plugin-transform-react-jsx'), { + useBuiltIns: true + }], + // function* () { yield 42; yield 43; } + [require.resolve('babel-plugin-transform-regenerator'), { + // Async functions are converted to generators by babel-preset-latest + async: false + }], + // Polyfills the runtime needed for async/await and generators + [require.resolve('babel-plugin-transform-runtime'), { + helpers: false, + polyfill: false, + regenerator: true, + // Resolve the Babel runtime relative to the config. + moduleName: path.dirname(require.resolve('babel-runtime/package')) + }] +]; // This is similar to how `env` works in Babel: // https://babeljs.io/docs/usage/babelrc/#env-option @@ -69,6 +69,16 @@ if (env === 'development' || env === 'test') { } if (env === 'test') { + // The following plugins are a temporary workaround because + // `babel-plugin-transform-regenerator` apparently needs them + // and `babel-preset-env` doesn't detect it. + // https://github.com/facebookincubator/create-react-app/issues/1156 + plugins.push.apply(plugins, [ + require.resolve('babel-plugin-transform-es2015-arrow-functions'), + require.resolve('babel-plugin-transform-es2015-destructuring'), + require.resolve('babel-plugin-transform-es2015-parameters') + ]); + module.exports = { presets: [ // ES features necessary for user's Node version diff --git a/packages/babel-preset-react-app/package.json b/packages/babel-preset-react-app/package.json index 9c0cd69bf60..e3b1ed91043 100644 --- a/packages/babel-preset-react-app/package.json +++ b/packages/babel-preset-react-app/package.json @@ -12,6 +12,9 @@ ], "dependencies": { "babel-plugin-transform-class-properties": "6.16.0", + "babel-plugin-transform-es2015-arrow-functions": "6.8.0", + "babel-plugin-transform-es2015-destructuring": "6.19.0", + "babel-plugin-transform-es2015-parameters": "6.18.0", "babel-plugin-transform-object-rest-spread": "6.19.0", "babel-plugin-transform-react-constant-elements": "6.9.1", "babel-plugin-transform-react-jsx": "6.8.0",