babel: Object rest spread not working correctly in object destructuring (T7086)

Issue originally made by @xinchaobeta

Bug information

  • Babel version: 6.4.5
  • Node version: v4.1.0
  • npm version: 2.14.3

Options

{
  "plugins": ["transform-object-rest-spread"]
}

Input code

let {a, b, ...c} = d

Description

the output code is

let { a, b, ...c } = d;

we expect

let {a, b} = d
let c = _objectWithoutProperties(d, ["a", "b"]);

In the above example, we have not include the es2015-destructuring , because we only want compile es7 to es6

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 23 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Since is this high priority + (given I’m working on https://github.com/babel/babel-preset-env and having to whitelist the destructuring/parameter transforms if using object spread sucks), I’m going to work on this.

Ok the PR is https://github.com/babel/babel/pull/4755

Can folks try the changes locally and report back?

Can test locally by replacing in node_modules: https://gist.github.com/hzoo/d269ccfd5758c556c900f47dd752cd61 - I just took the code that changed in src and ran it in the babel repl in loose mode

replace node_modules/babel-plugin-transform-object-rest-spread/lib/index.js

Comment originally made by @morlay

Just Note:

babel-plugin-transform-es2015-spread, babel-plugin-transform-es2015-parameters and babel-plugin-transform-es2015-destructuring are required, if we write code like below:

const fn = ({ a, ...otherProps }) => otherProps;

fn({ a: 1, b: 2 });

Tested in Node 6 with babel@6