jhen0409 / babel-preset-es2015-node6

Babel preset to make node@6 fully ES2015 compatible.
MIT License
132 stars 4 forks source link

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

Open olalonde opened 8 years ago

olalonde commented 8 years ago

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 commented 8 years ago

Think I got it to work with:

{
  "presets": ["es2015-node6"],
  "plugins": [
    "babel-plugin-transform-es2015-destructuring",
    "transform-object-rest-spread"
  ]
}
jhen0409 commented 8 years ago

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

Keep this issue open. :)

ssova-4xxi commented 8 years ago

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

olalonde commented 8 years ago

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

jhen0409 commented 8 years ago

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

I'll try to fix it this week.

olalonde commented 8 years ago

@jhen0409 thanks :)

jhen0409 commented 8 years ago

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.

hzoo commented 8 years ago

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

antitoxic commented 8 years ago

What's preventing this issue from being closed?

olalonde commented 8 years ago

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.

Billy- commented 8 years ago

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

antitoxic commented 8 years ago

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

Billy- commented 8 years ago

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.

olalonde commented 8 years ago

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 }]
  ]
}
Billy- commented 8 years ago

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...

dtothefp commented 8 years ago

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

ahmed1490 commented 8 years ago

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

klimashkin commented 7 years ago

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

hzoo commented 7 years ago

Yep it should work now without the 2 plugins!

deadbeef84 commented 7 years ago

@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 babel-plugin-transform-object-rest-spread@6.19.0 is installed.

christophehurpeau commented 7 years ago

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

hzoo commented 7 years ago

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.

juanpaco commented 7 years ago

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 babel-plugin-transform-object-rest-spread@6.20.2.

olalonde commented 7 years ago

@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".

klimashkin commented 7 years ago

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