Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having problems with Spread Operator #13

Closed
diego-toro opened this issue Jun 28, 2015 · 10 comments
Closed

Having problems with Spread Operator #13

diego-toro opened this issue Jun 28, 2015 · 10 comments

Comments

@diego-toro
Copy link

Hi,
I just came to Atom world from Sublime and I'm trying to compile a .jsx component and when I try to save it always appears this message

Babel v5.6.15 Transpiler Error
/app/components/Lane.jsx: Unexpected token (35:18)

The line that is broking

const {i, name, ...props} = this.props;

Referring the spread operator.

@gandm
Copy link
Owner

gandm commented Jun 28, 2015

This is nothing to do with language-babel. That message is passed back from the Babel API. I would imagine you would also get this message from the Babel CLI. You have to enable the spread transformer es6.spread or set the stage to enable it. Either use the babelrc files or set via settings.

@gandm
Copy link
Owner

gandm commented Jun 28, 2015

spread as a lhs?

@diego-toro
Copy link
Author

I'm using webpack so I just disabled the transpile and that's it, but I'm still wondering about it, I was using a destructuring with "..." to keep the props and with webpack is working well.

And... Sorry may I ask What is lhs?

@mathieumg
Copy link

What is lhs?

Left-hand side

@gandm
Copy link
Owner

gandm commented Jun 28, 2015

The LHS spread should be an array.
e.g
[ a, b, ...c ] = this.props

@gandm
Copy link
Owner

gandm commented Jun 28, 2015

Sorry I misunderstood what you were doing. Yes this should work if the correct stage is set in either babelrc or settings.

@diego-toro
Copy link
Author

ooooo yes, but I'm using destructuring also https://babeljs.io/docs/learn-es2015/#destructuring like this

bla=>{
  const {a, b, ...props} = this.props;
}

@diego-toro
Copy link
Author

yeah, but I don't know where to put it on settings, Just now I think I broke Atom.

@gandm
Copy link
Owner

gandm commented Jun 28, 2015

This is experimental stage 1 or use transformer es7.objectRestSpread https://github.com/sebmarkbage/ecmascript-rest-spread

You can set this in .babelrc file or language-babel settings. In language Babel's settings put es7.objectRestSpread in the Optional Transformers field Or use stage 1
In babelrc use stage 1 or use the 'optional' option.

I've never used the webpack loader so I don't know why this works without these settings. I may have a look given time.

@diego-toro
Copy link
Author

Thanks a lot!!!
It works awesome in Optional Transformers and I just added another one

es7.objectRestSpread, es7.decorators

@gandm gandm closed this as completed Jun 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants