IntelliJ IDEA and backticks (`)
Asked Answered
E

2

6

In our environment, we write template Javascript which has areas where server pre-processing inserts values into the code.

An example would look like this:

    var myVarValue = "`serverProcessedVarValue()`";

In the above, the server runs the function demarcated by the backticks and writes the result between the quotes, then ships that javascript off to the browser.

We use IntelliJ IDEA. It (and Webstorm, I'm assuming) highlights these backticks as a coding error. I can't find a setting to change that behavior. Is there one?

Thanks!

Espadrille answered 28/7, 2015 at 15:23 Comment(2)
IntelliJ is probably thinking that you're writing valid JavaScript in there. Is it the case that you want to be able to execute it as a JS file, or is it exclusively for templating?Kenon
Well, I'm not sure I understand your question. But, the file seen in the IDE must be valid Javascript -- apart from the backticks. Of course, the production JS is a result of the parsing of this file on the server. So, I guess you could say the file in the IDE is solely for templating. But, its contents need to pass muster.Espadrille
Z
1

There is no such setting. IntelliJ IDEA builds a complete syntax tree for the file you're editing, and all of its features rely on having the complete syntax tree. Because of that, it's not possible to tell it to ignore certain characters - it would not know how to parse the remaining code and how to validate the resulting syntax tree.

What you can do is either write a plugin to parse your specific flavor of JavaScript with templates, or change the syntax you're using to match one of the template languages already supported by IntelliJ IDEA.

Zerline answered 29/7, 2015 at 6:40 Comment(0)
T
5

Backtick is supported in ES6 for multi-line string and there is a "JavaScript language version" settings in WebStorm. Changing it to ES6, will change that behavior.

Thrive answered 5/11, 2015 at 10:40 Comment(0)
Z
1

There is no such setting. IntelliJ IDEA builds a complete syntax tree for the file you're editing, and all of its features rely on having the complete syntax tree. Because of that, it's not possible to tell it to ignore certain characters - it would not know how to parse the remaining code and how to validate the resulting syntax tree.

What you can do is either write a plugin to parse your specific flavor of JavaScript with templates, or change the syntax you're using to match one of the template languages already supported by IntelliJ IDEA.

Zerline answered 29/7, 2015 at 6:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.