From 22f9fe0d33dded7ec5a361ef08f69167874a4eb7 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sun, 14 Jan 2018 15:37:00 +0000 Subject: [PATCH] Always include destructuring transform (#3788) * Always include destructuring transform * Fix lint --- packages/babel-preset-react-app/index.js | 4 ++++ packages/babel-preset-react-app/package.json | 1 + .../kitchensink/src/features/syntax/ObjectDestructuring.js | 4 +++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/babel-preset-react-app/index.js b/packages/babel-preset-react-app/index.js index 0d961af6f0f..d90fb6af50b 100644 --- a/packages/babel-preset-react-app/index.js +++ b/packages/babel-preset-react-app/index.js @@ -7,6 +7,10 @@ 'use strict'; const plugins = [ + // Necessary to include regardless of the environment because + // in practice some other transforms (such as object-rest-spread) + // don't work without it: https://github.com/babel/babel/issues/7215 + require.resolve('babel-plugin-transform-es2015-destructuring'), // class { handleClick = () => { } } require.resolve('babel-plugin-transform-class-properties'), // The following two plugins use Object.assign directly, instead of Babel's diff --git a/packages/babel-preset-react-app/package.json b/packages/babel-preset-react-app/package.json index f020f99e0b8..23c22142334 100644 --- a/packages/babel-preset-react-app/package.json +++ b/packages/babel-preset-react-app/package.json @@ -14,6 +14,7 @@ "babel-plugin-dynamic-import-node": "1.1.0", "babel-plugin-syntax-dynamic-import": "6.18.0", "babel-plugin-transform-class-properties": "6.24.1", + "babel-plugin-transform-es2015-destructuring": "6.23.0", "babel-plugin-transform-object-rest-spread": "6.26.0", "babel-plugin-transform-react-constant-elements": "6.23.0", "babel-plugin-transform-react-jsx": "6.24.1", diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ObjectDestructuring.js b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ObjectDestructuring.js index be519175f69..14b06f7a4cc 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ObjectDestructuring.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/syntax/ObjectDestructuring.js @@ -40,7 +40,9 @@ export default class extends Component { return (
{this.state.users.map(user => { - const { id, name } = user; + const { id, ...rest } = user; + // eslint-disable-next-line no-unused-vars + const [{ name, ...innerRest }] = [{ ...rest }]; return
{name}
; })}