【问题标题】:ES6 syntax unrecognized by Visual Studio CodeVisual Studio Code 无法识别 ES6 语法
【发布时间】:2016-01-31 03:31:16
【问题描述】:

应用程序在 nodejs v4.2.1 上运行良好,但我无法让 Visual Studio Code 识别 ES6 语法,例如 class。是否有任何额外的配置可以让 Visual Studio Code 在设计时识别 ES6 语法?

./root/dir/task.js

'use strict'

class Task { // <-- Parsing error: Unexpected reserved word (undefined)
  constructor(name) {
    this.name = name;
    this.completed = false;
  };

  complete() {
    console.log('Completing: ' + this.name);
    this.completed = true;
  };

  save() {
    console.log('Saving: ' + this.name);
  };
}

module.exports = Task;

我还有一个jsconfig.json,就像this page suggests

./root/jsconfig.json

{
    "compilerOptions": {
        "target": "ES6",
        "module": "commonjs"
    }
}

【问题讨论】:

    标签: node.js ecmascript-6 visual-studio-code


    【解决方案1】:

    截至 Visual Studio 代码的最新版本..(12 月发布)ES6 支持是主要的。意味着不需要 jsconfig.json。 您正在使用哪个版本的代码?

    参考https://code.visualstudio.com/updates/(ES6 是新的默认值)。

    前段时间,项目中的每个子文件夹的代码都需要 jsconfig.json 用于语法高亮显示。

    希望对你有帮助

    【讨论】:

    • 我在那个版本上,我在输入时确实有语法突出显示和通过智能感知提供的建议。它甚至在我开始输入时建议class...它只是在完全输入后加下划线。
    • 你安装了任何扩展的 vs 代码插件吗?如果是这样,您可以禁用它并尝试重新启动代码吗?立即查看
    猜你喜欢
    • 2020-04-01
    • 1970-01-01
    • 2018-03-28
    • 2020-01-12
    • 2021-09-02
    • 2016-01-23
    • 1970-01-01
    • 1970-01-01
    • 2022-07-15
    相关资源
    最近更新 更多