Visual Studio Code无法识别的ES6语法 [英] ES6 syntax unrecognized by Visual Studio Code

查看:63
本文介绍了Visual Studio Code无法识别的ES6语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该应用程序在nodejs v4.2.1上运行良好,但是我无法获得Visual Studio Code来识别ES6语法,例如 class .是否有任何其他配置可以在设计时通过Visual Studio Code识别ES6语法?

./root/dir/task.js

 严格使用"class Task {//<-解析错误:意外的保留字(未定义)构造函数(名称){this.name =名称;this.completed = false;};完全的() {console.log('Completing:'+ this.name);this.completed = true;};保存() {console.log('Saving:'+ this.name);};}module.exports =任务; 

我还有一个 jsconfig.json ,如

解决方案

从Visual Studio代码的最新版本开始.(12月发行)主要支持ES6.表示不需要jsconfig.json.您正在使用哪个版本的代码?

引用 https://code.visualstudio.com/updates/(ES6是新的默认设置).

有时,代码需要对项目中的每个子文件夹使用jsconfig.json来突出显示语法.

希望这会有所帮助

The application runs fine with nodejs v4.2.1, but I cannot get Visual Studio Code to recognize ES6 syntax, like class. Is there any extra configuration to get ES6 syntax recognized at design time by Visual Studio Code?

./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;

I also have a jsconfig.json, as this page suggests.

./root/jsconfig.json

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

解决方案

As of the latest version of visual studio code.. ( December release) ES6 support is primary. Means no need for jsconfig.json. Which version of code your are using?

Refer https://code.visualstudio.com/updates/ ( ES6 is new default ).

Some time back, code need jsconfig.json for every sub folders in your project for syntax highlighting.

Hope this helps

这篇关于Visual Studio Code无法识别的ES6语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆