jonsmithers / vim-html-template-literals

Syntax highlighting for html template literals in javascript (as in lit-html and polymer 3)
MIT License
71 stars 10 forks source link

Highlighting not reset in some cases #17

Closed timonson closed 4 years ago

timonson commented 4 years ago

Hi @jonsmithers, in some cases the plugin doesn't reset the highlighting, it seems. For example in the following code, the function declaration is highlighted incorrectly.

/*
 * @param {{ interval?: number, timeout?: number }} [options] timeout and polling interval
 */
function waitForPredicate() {}

When I disable the plugin, it works correctly again. I have noticed similar effects at some other occasions, as well. On one accasion I had a file where I put a template literal at the top and the rest of the javascript code was incorrectly highlighted after that. If you want me to give you any more information, please let me know.

jonsmithers commented 4 years ago

That's very interesting. I can totally reproduce it. For some reason, the javascript syntax kind of doubles-up in a weird way on the curly braces in the jsdocs.

I think this is because vim-html-template-literals causes syntax/javascript.vim to get sourced twice. Vim sources it naturally the first time (because you opened a js file), and then vim-html-template-literals sources syntax/html.vim which internally sources syntax/javascript.vim again, since html can contain javascript. I had incorrectly assumed that this was harmless.

This should be fixed now on the dev branch.