I have an ES6 template string, which represents JS code. If I put <script> tags around it, JetBrains IntelliJ will do syntax highlighting and checking, but not if there are no script tags.
Is there a way to tell JetBrains IDE how to interpret the template string?

It's definitely the presence/absence of the html tag.
IDEA auto-injects HTML in JavaScript string literals/template string if there are HTML tags in it; to inject other languages, you need adding language injection manually - for example, the language can be temporary injected via Inject language or reference intention available on Alt+Enter:

You can also annotate your injection with comments to make it permanent:
//language=JS
const baz = `console.log("test")`
See https://www.jetbrains.com/help/idea/using-language-injections.html for more information
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With