Visual Studio Code无法识别ES6语法

问题描述 投票:2回答:1

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

./root/敌人/task.就是

'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/就是config.JSON

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

enter image description here

node.js ecmascript-6 visual-studio-code
1个回答
0
投票

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

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

一段时间后,代码需要jsconfig.json用于项目中的每个子文件夹以进行语法突出显示。

希望这可以帮助

© www.soinside.com 2019 - 2024. All rights reserved.