react-webpack-generators / generator-react-webpack

Yeoman generator for ReactJS and Webpack
http://newtriks.com/2013/12/31/automating-react-with-yeoman-and-grunt/
MIT License
2.87k stars 355 forks source link

Destructuring assignment support #177

Closed firebait closed 8 years ago

firebait commented 8 years ago

Hi,

I tired to do the following on a component:

let { disabled, ...other } = this.props;

and got the following:

Module build failed: SyntaxError: /xxx.jsx: Unexpected token (26:20)
  24 |   render () {
> 25 |     let { disabled, ...other } = this.props;
     |                     ^

Any ideas would be helpful. I tried adding options to the .eslintrc file with no avail.

stylesuxx commented 8 years ago

Hey @firebait, .eslintrc is only for the lint settings.

What you are trying to to is to spread rest properties, this is not part of es2015 but is a state 2 proposal, so just install the state 2 presets:

npm install babel-preset-stage-2 --save-dev

and activate them via .babelrc:

{
  "presets": [
    "es2015",
    "react",
    "stage-2"
  ]
}

and you should be good to go.

firebait commented 8 years ago

Thanks @stylesuxx that did it.

thibault commented 8 years ago

This thread solved the problem for me. Since I was also searching the correct eslintrc config to recognize the spread operator, I will leave this here for the ones who will follow me:

// ~/.eslintrc.js
module.exports = {
  'parserOptions': {
    'ecmaFeatures': {
      'experimentalObjectRestSpread': true
    }
  }, …