From f8c9cd39f9046c1d773dcbc469cd906ee1bf5fc8 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 6 Dec 2016 14:45:46 +0000 Subject: [PATCH] Fix Babel issues in tests by applying the right transforms --- packages/babel-preset-react-app/index.js | 22 +++++++++----------- packages/babel-preset-react-app/package.json | 2 -- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/babel-preset-react-app/index.js b/packages/babel-preset-react-app/index.js index 0188b9484c1..a028babc06c 100644 --- a/packages/babel-preset-react-app/index.js +++ b/packages/babel-preset-react-app/index.js @@ -23,11 +23,6 @@ const plugins = [ [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, @@ -69,13 +64,10 @@ 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'), + // We always include this plugin regardless of environment + // because of a Babel bug that breaks object rest/spread without it: + // https://github.com/babel/babel/issues/4851 require.resolve('babel-plugin-transform-es2015-parameters') ]); @@ -100,7 +92,13 @@ if (env === 'test') { // JSX, Flow require.resolve('babel-preset-react') ], - plugins: plugins + plugins: plugins.concat([ + // function* () { yield 42; yield 43; } + [require.resolve('babel-plugin-transform-regenerator'), { + // Async functions are converted to generators by babel-preset-latest + async: false + }], + ]) }; if (env === 'production') { diff --git a/packages/babel-preset-react-app/package.json b/packages/babel-preset-react-app/package.json index e3b1ed91043..b61315e1916 100644 --- a/packages/babel-preset-react-app/package.json +++ b/packages/babel-preset-react-app/package.json @@ -12,8 +12,6 @@ ], "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",