How to get Webstorm 11 to recognize ES2015 javascript in HTML script tags

耗尽温柔 提交于 2019-12-08 15:14:52

问题


I've been having trouble getting WebStorm 11 to recognize/highlight/parse ES6/ES2015 javascript when it's inside script tags in regular HTML. Can't find a setting that seems to apply to this. Thanks in advance for your time.

For example, the following js is inside a script tag. You'll notice that WebStorm thinks that a whole bunch of things are broken with it, but it executes just fine.


回答1:


Using <script type="text/ecmascript-6"> rather than <script type="text/javascript"> should help you.

Issue on JetBrans YouTrack on the topic.

UPD:

It looks like a WebStorm bug (tested on the latest release):

  var a = (d) => {}; //OK
  a.v('c', (d) => {}); // OK
  class Test {
    doSmth(){
      a.sh('ff', (d) => {});
      //            ^^^^^^ , or ) expected when in <script>
      //            100% OK when in a js file
    }
  }

I think you could contact JetBrains support, probably they will fix it.

But anyways, I do not think it's a good practice to have JS in your HTML and, moreover, ES6 which is not yet commonly supported.

UPD 2:

As posted in comments by, zigomir, you might want to use type="text/babel" instead of type="text/ecmascript-6" in .vue files or otherwise linting wouldn't work.



来源:https://stackoverflow.com/questions/33722779/how-to-get-webstorm-11-to-recognize-es2015-javascript-in-html-script-tags

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