3

I have .js file running in Visual Studio Code 1.4.0

But when I do this

var test = state.selectedStorage.storageItems.map(i => {
          if(i.id != action.payload) return i;
          return {
              ...i,
              qty: i.qty - 1
          }
      });

I get an underline under the 3 dots(property assignment expected). When I try to do an npm start I get

 Unexpected token (134:18) 

this is my webpack.config.js

module.exports = {
  devtool: 'inline-source-map',
  entry: "./app/index.js",
  output: {
    path: __dirname + '/dist',
    filename: "bundle.js"
  },
  devServer: {
    contentBase: "./app",
    inline: true,
    port: 3333
  },
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        query: {
          presets: ['es2015', 'react']
        }
      },
      {
        test: /\.scss$/,
        loaders: ['style', 'css', 'sass']
      },
      {
        test: /\.woff($|\?)|\.woff2($|\?)|\.ttf($|\?)|\.eot($|\?)|\.svg($|\?)/,
        loader: 'url-loader'
      }
    ]
  },
   externals: {
    jquery: 'jQuery'
  },
} 
Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153
chobo2
  • 83,322
  • 195
  • 530
  • 832
  • Possible duplicate of [Browserify, Babel 6, Gulp - Unexpected token on spread operator](http://stackoverflow.com/questions/33745118/browserify-babel-6-gulp-unexpected-token-on-spread-operator) – Felix Kling Aug 12 '16 at 20:13

2 Answers2

1

The Object rest/spread operator is not a part of ES2015. It is however supported by babel using the required plugin.

Amit
  • 45,440
  • 9
  • 78
  • 110
  • 1
    Yes. I now have that plugin but still does not stop the ide from actually thinking it is still an error. when I run it is fine. Just Visual studio code does not understand it. – chobo2 Aug 12 '16 at 20:25
  • 1
    https://code.visualstudio.com/docs/languages/javascript#_disable-syntax-validation-when-using-non-es6-constructs – Steffen Aug 13 '16 at 19:36
1

From the Visual Code Studio doc page (in the common questions, the one about React Native):

React Native examples often use the experimental Object Rest/Spread operator. This is not yet supported by VS Code. If you want to use it, it is recommended that you disable the built-in syntax checking (see below).

Source: https://code.visualstudio.com/docs/languages/javascript

qur2
  • 450
  • 5
  • 9
  • Oh, just realised your issue is not about VSC, but about Babel. Amit's answer is the correct one then. Mine answers your comment you left to his answer. – qur2 Oct 05 '16 at 15:08