jeffling / wallaby-webpack

webpack preprocessor for wallabyjs
25 stars 8 forks source link

`SyntaxError: Unexpected token` on spread attributes #6

Closed okonet closed 9 years ago

okonet commented 9 years ago

Not sure if this is wallaby-webpack related or should be reported in wallaby-public.

Following code is failing to be parsed:

let { type, className, isSelected, ...rest } = this.props

Error message:

Failed to parse js/modules/global/EntityComponent.jsx, SyntaxError: Unexpected token (37:43)

I'm using following preprocessor:

var babelTransformer = (file) => {
  return babel.transform(file.content, {
    sourceMap: true,
    experimental: true,
    optional: ['runtime']
  });
}
ArtemGovorov commented 9 years ago

Object rest/spread is a proposal for ES7 (https://github.com/sebmarkbage/ecmascript-rest-spread) and wallaby currently only supports ES6. All I can suggest for now as a workaround is not to use experimental ES7 features (they may actually change in future), and use alternative ES6 features. For example, this should work (in the latest wallaby version): let [ type, className, isSelected, ...rest ] = this.props

Having said that, I'm happy to support ES7 in wallaby. Here is the current situation: babel does support some ES7 features and wallaby is using the same code parser as babel (https://github.com/babel/acorn-babel), but wallaby needs to generated instrumented code before babel preprocessor and it uses escodegen fork (https://github.com/wallabyjs/escodegen) to do that. Escodegen doesn't yet support ES7, that's the only thing required in order to support ES7 in wallaby. I am happy to accept PR requests to https://github.com/wallabyjs/escodegen with ES7 code support. What's basically required is to add a few generate functions to support ES7 AST elements, such as SpreadProperty (in your example).

okonet commented 9 years ago

Actually I was hoping to have webpack me covered since I use the --experimental flag in webpack config. But the webpack's loaders doesn't seem to be working either... But I guess this is how wallaby works, using it's own parser and not the webpack's processed output.

ArtemGovorov commented 9 years ago

Yes, wallaby has to instrument the original code, not the processed one, to provide the code coverage correctly (source maps data is not enough for doing the coverage).

ArtemGovorov commented 9 years ago

@okonet Now it is supported via compilers https://github.com/wallabyjs/public#compilers-setting

screen shot 2015-04-10 at 12 26 43 pm

okonet commented 9 years ago

:+1: Thanks! I'll take a look