Javascript formatting inside html

Answered

Hi, 

I'm trying to develop a polymer app with es6 as described here: https://www.polymer-project.org/1.0/articles/es6.html

The major problem is that Intellij Idea completely screws up es6 code, especially lambdas, when it's put inside html. Inside js files it's formatted quite ok. 

Is there any way to tell Intellij Idea to format js code insde html in the same way as in js files?

 

Best regards, Eugene.

7 comments
Comment actions Permalink

PS: In Languages&Frameworks Javascript language version is set to ECMAScript 6.

And it also reports false errors for es6 inside html.  

0
Comment actions Permalink

as formatting is based on code tree built by parser, code that can't be parsed correctly would be broken on attempt to format it. So, most probably the problem is that ES6 embedded in HTML is treated as pure javascript. What script type do you use in your HTML (<script type="">)?

0
Comment actions Permalink

I didn't use any, after putting

type="text/ecmascript-6"

errors are gone and fortmatting seems to work to. 

Thank you very much!

1
Comment actions Permalink

i see, thanks for update:) If the type is not explicitly specified, "text/javascript" is assumed. See https://youtrack.jetbrains.com/issue/WEB-16444

0
Comment actions Permalink

I found I have to use both the text/ecmascript-6 and text/javascript type directives for (current) Chrome and Firefox to run HTML embedded script:

<script type="text/javascript" type="text/ecmascript-6">
1
Comment actions Permalink

Agreed Dan, and this is not ideal. The last thing I want is to add markup that is IDE-specific.

IntelliJ, are there any plans to allow us to specify which version of ECMAScript gets parsed via settings?

Adding two type attributes really doesn't work, and using only text/ecmascript-6 seems to break imports.

0

Please sign in to leave a comment.