Templated JavaScript files & syntax

Right now I'm evaluating WebStrom, but I'm saddled with quite a few JavaScript files that still use template markup for i18n and including other files. This is using Perl's TemplateToolkit, so all over the place I've got '[% PROCESS myModule.js %]' instructions. Obviously not a good situation for syntax checking, linting etc.

Anyway to work around this? I could imagine a plugin working, but that sounds like quite a big deal - unless it's possible to just strip out the superfluous parts and pass it on to the regular JavaScript parts.


Maybe it's possible to insert template directives like [% PROCESS myModule.js %] in such places of code that it wouldn't break syntax of language.
For example such places are inside string literals or comments.


Well, for internationalization, that's certainly a viable way and I'd say most of those strings (passed by e.g. the webapp controller) are in proper JS strings already, so no problem there. But if you're including some other JS file within a comment or string, that would just create a bunch of syntax errors (e.g. if I include a function in a single-line comment, the first line would be commented out). That would only work if the template engine itself would remove the comment beforehand.Sure, some simple macro-like search and replace so that you don't get errors while editing a file might work out, too, but that would still ruin checking syntax and references over the whole code.

I'm basically looking for a possible workaround that only affects WebStorm, so you don't need an additional build/deploy step or modifications to the server-side code. Or otherwise you'd just add a lot of unnecessary cruft for the users who don't have syntax-checking IDEs. Don't want to annoy any vim-/emacs-users. They're quick to anger.


As stated in http://template-toolkit.org/docs/manual/Syntax.html

You can change the tag characters using the START_TAG, END_TAG and TAG_STYLE configuration options.

So you can replace [% with /*[ and %] with ]*/ and have valid JavaScript code.
If you would like to have support for [% and %] character sequences please file an issue in the http://youtrack.jetbrains.com/issues/WI#newissue=yes .


Like I said, I'd prefer something that wouldn't require global changes that every developer has to adhere to.

Theoretically, it shouldn't even be too hard, considering that WebStorm already does something like that. Within your average HTML file, you can have separate script and style sections, all with their individual syntax highlighting. So adding something like template support should seem possible, I just don't know whether the needed "hooks" into the engine are exposed.

But I'll have a look at the plugin docs, and maybe I'll even get some support about changing the template tags from other developers using IDEs…


Please sign in to leave a comment.