ES6 / ES7 support in Visual Studio 2015 Community

本秂侑毒 提交于 2019-11-28 08:09:25

I was having this problem in .jsx files, visual studio 2015 was using the react-tools plugin to parse and highlight the syntax errors.

I can't find the question i got this from now, but someone said to change a line in the following file:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\react-server\server.js

Change the following line:

var transformed = reactTools.transformWithDetails(code, { elementMap: true });

To:

var transformed = reactTools.transformWithDetails(code, 
    { elementMap: true, 
      es6module: "--es6module", 
      harmony: "--harmony", 
      nonStrictEs6module: "--non-strict-es6module"  });

I added the option nonStrictEs6module, and now it doesn't warn me over most things except directly assigned arrows functions:

It would be nice if we could somehow I managed to swap out the react-tools transform for a babel stage-1 transformer, check out my answer here :-)

Javascript is a language. ES6 is a version of Javascript. Microsoft has not supplied a intellisense mapping file for it. The suggestions on this post suggest using javascript frameworks/APIs which do provide intellisense mapping files. These suggestions do not answer the question on how to stop getting intellisense errors for new Javascript versions. Unless someone creates that mapping file and provides a URL for us to reference from Visual Studio/tools/Javascript/Intellisence/references you will get syntax errors writing straight ES6 Javascript.

For using the new ES6/ES7 syntax you have to use a transpiler. You have three options Traceur, Babel or TypeScript. These will transpile the new syntax to the current ES5 syntax which the current browsers support. Aurelia has good support for Babel or TypeScript.

Visual Studio 2015 includes TypeScript 1.5. So you have to create a TypeScript file (.ts) instead of a Javascript file (.js). TypeScript will transpile this to a ES5 .js file. The .js file is the one that runs in the browser.

When you open a Javascript file in Visual Studio it will handle this as a ES5 Javascript file and not as a ES6/ES7 Javascript file, so if you want to use Babel then you get syntax errors in the editor.

I think the issue is the nodeJS project template. I have created an empty web project and used git bash to run my jspm commands. When I add a js file I still get a couple of syntax issues but it recognizes most of the new syntax.

ahmadalibaloch

The best thing I can suggest is the

WebCompiler. Its the most easy and beautiful way to write ES6 or LESS or TypeScript etc.

The easiest and most powerful way to compile LESS, Scss, JSX and CoffeeScript files directly within Visual Studio or through MSBuild.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!