babel-preset-es2015-node6 icon indicating copy to clipboard operation
babel-preset-es2015-node6 copied to clipboard

Doesn't work with transform-object-rest-spread

Open olalonde opened this issue 8 years ago • 25 comments

Anyone managed to get this preset to work with https://babeljs.io/docs/plugins/transform-object-rest-spread/?

Seems it works fine for spread but doesn't work for rest. I'm guessing I need to install an additional preset. Reported here as well: https://phabricator.babeljs.io/T7316

olalonde avatar Apr 26 '16 23:04 olalonde

Think I got it to work with:

{
  "presets": ["es2015-node6"],
  "plugins": [
    "babel-plugin-transform-es2015-destructuring",
    "transform-object-rest-spread"
  ]
}

olalonde avatar Apr 26 '16 23:04 olalonde

You're right, I'll add back transform-es2015-destructuring, until this issue is resolved.

Keep this issue open. :)

jhen0409 avatar Apr 27 '16 00:04 jhen0409

Node.js@6 has destructing support! http://node.green

ssova-4xxi avatar Apr 29 '16 08:04 ssova-4xxi

@ss4xxi it does... The issue is that transform-object-rest-spread doesn't work without transform-es2015-destructuring for some reason.

olalonde avatar Apr 30 '16 18:04 olalonde

This playground can simply reproduce the problem. Also I commented on T7316.

I'll try to fix it this week.

jhen0409 avatar May 03 '16 22:05 jhen0409

@jhen0409 thanks :)

olalonde avatar May 04 '16 00:05 olalonde

Now T7316 is merged to T7086.

It looks transform-es2015-parameters is also required, maybe we can split to new file, use es2015-node6/object-rest as a short-term solution?

UPDATED I splitted destructuring, parameters to es2015-node6/object-rest on v0.2.0, or you can still use v0.1.

jhen0409 avatar May 04 '16 03:05 jhen0409

Object rest spread depends on destructuring so we would have to rewrite it to be independent of it

hzoo avatar May 05 '16 15:05 hzoo

What's preventing this issue from being closed?

antitoxic avatar Oct 16 '16 08:10 antitoxic

Probably because Babel still requires additional plugins for object rest spread to work (https://github.com/babel/babel/issues/4074), babel-plugin-transform-es2015-destructuring and babel-plugin-transform-es2015-parameters which are otherwise not required for Node v6.

olalonde avatar Oct 17 '16 16:10 olalonde

After many hours searching for info and lots of trial and error, I have tried every combination of plugins and presets possible, yet none of them have worked. Can someone please confirm a set up that works? I am compiling for the browser and am running webpack in Node V6.2.2

Billy- avatar Oct 28 '16 14:10 Billy-

@Billy- Use es2015 for browser bundle and es2015-node6/object-rest for node.

antitoxic avatar Oct 28 '16 14:10 antitoxic

As I said, I have tried every combination of plugins and presets I have come across. My most recent babelrc file contains es2015 preset (and react), transform-es2015-destructuring and transform-object-rest-spread plugins.

Billy- avatar Oct 28 '16 15:10 Billy-

Can you share your .babelrc file and what parsing error you are getting? I'm using:

{
  "presets": ["eslatest-node6"],
  "plugins": [
    "transform-es2015-destructuring",
    "transform-es2015-parameters",
    ["transform-object-rest-spread", { "useBuiltIns": true }]
  ]
}

olalonde avatar Oct 28 '16 17:10 olalonde

Sorry guys, false alarm.. Not sure what was going on at work earlier. Pulled down my WIP and it worked :angry:. I reduced down my .babelrc and it actually works with only the object rest spread transform plugin:

{
  "presets": [
    "es2015",
    "react"
  ],
  "plugins": [
    "transform-object-rest-spread"
  ]
}

Will try to replicate the issue at work on Monday...

Billy- avatar Oct 28 '16 18:10 Billy-

https://github.com/build-boiler/build-boiler/blob/master/packages/boiler-config-babelrc/node-6.json

dtothefp avatar Oct 28 '16 18:10 dtothefp

trying to get it working for node..

    "babel-plugin-transform-es2015-destructuring": "^6.18.0",
    "babel-plugin-transform-object-rest-spread": "^6.16.0",
    "babel-preset-es2015": "^6.18.0",
    "babel-preset-stage-0": "^6.16.0",
    "babel-register": "^6.18.0",
{
  "presets": ["es2015", "stage-0"],
  "plugins": ["transform-es2015-destructuring", "transform-object-rest-spread"]
}

and it still complains Syntax Error

ahmed1490 avatar Oct 31 '16 12:10 ahmed1490

https://github.com/babel/babel/releases/tag/v6.19.0 "Make the plugin work standalone with parameters/destructuring plugins"

klimashkin avatar Nov 16 '16 19:11 klimashkin

Yep it should work now without the 2 plugins!

hzoo avatar Nov 16 '16 19:11 hzoo

@hzoo can you confirm this is actually working? I'm using "presets": ["es2015-node6", "stage-0"] but still get SyntaxError: Unexpected token .... It's working as expected with es2015-node6/object-rest. I've confirmed that [email protected] is installed.

deadbeef84 avatar Nov 22 '16 15:11 deadbeef84

@deadbeef84 can be related: https://github.com/babel/babel/pull/4883

christophehurpeau avatar Nov 22 '16 15:11 christophehurpeau

can you confirm this is actually working

You can test in the repl - it would be useful you can post the relevant code too. The transform basically had to be rewritten for rest so it's likely some cases were missed.

hzoo avatar Nov 22 '16 16:11 hzoo

I love babel, and thanks for the work on it!

I'm coming across a similar error. I was following https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters#Destructuring_rest_parameters, and in Babel, I'm unable to get either of the following to work (SyntaxError is the result):

function foo(a, b, ...[ c, d ]) { }
function foo(...[ c, d ]) { }

I don't know if those are intended to work with the solo object rest spread plugin. I'm running [email protected].

juanpaco avatar Dec 19 '16 18:12 juanpaco

@juanpaco I think it's this bug: https://github.com/babel/babel/issues/4851 .. work around is to "use the parameter/destructuring transforms until it's fixed".

olalonde avatar Dec 19 '16 21:12 olalonde

Since Babel 6.22 transform-object-rest-spread works fine finally, there is no need to use es2015-node6/object-rest preset anymore, just es2015-node6 is quite enough.

I think this issue and #4 can be closed

klimashkin avatar Jan 21 '17 00:01 klimashkin