【问题标题】:How to enable support for spread operator feature in Visual Studio Code?如何在 Visual Studio Code 中启用对扩展运算符功能的支持?
【发布时间】:2016-12-19 21:49:53
【问题描述】:

我在 Visual Studio Code 1.4.0 中运行 .js 文件

但是当我这样做时

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

我在 3 个点下加了一个下划线(预期的属性分配)。当我尝试做 npm start 时,我得到了

 Unexpected token (134:18) 

这是我的 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'
  },
} 

【问题讨论】:

标签: javascript webpack ecmascript-6 visual-studio-code spread-syntax


【解决方案1】:

Object rest/spread operator 不是 ES2015 的一部分。但是 babel 使用 required plugin 支持它。

【讨论】:

  • 是的。我现在有了那个插件,但仍然没有阻止 ide 实际上认为它仍然是一个错误。当我运行它很好。只是Visual Studio代码看不懂。
【解决方案2】:

来自 Visual Code Studio 文档页面(在常见问题中,关于 React Native 的问题):

React Native 示例经常使用实验性的 Object Rest/Spread 运算符。 VS Code 尚不支持此功能。如果您想使用它,建议您禁用内置语法检查(见下文)。

来源:https://code.visualstudio.com/docs/languages/javascript

【讨论】:

  • 哦,刚刚意识到您的问题不是关于 VSC,而是关于 Babel。那么阿米特的答案是正确的。我的回答您对他的回答留下的评论。
猜你喜欢
  • 2015-11-22
  • 1970-01-01
  • 2020-12-23
  • 2018-05-19
  • 2012-11-30
  • 1970-01-01
  • 1970-01-01
  • 2021-11-22
  • 1970-01-01
相关资源
最近更新 更多