Sublime Forum

How to make a good fix for JavaScript.sublime-syntax failing to recognize closures in construction (new)?

#1

When I do this with JavaScript highlighting:
new function() { let x = 10; console.log(x); }
The keyword function is not highlighted because new expects an identifier. I’ve looked at JavaScript.sublime-syntax in the JavaScript package but I am not sure of how to solve this well or without experimentation. So I wanted to know if there is any quick tweak I can do to allow closures in construction using new if that is how I can have function be highlighted in the above example. Any ideas?

I know I may be suggested against constructing with closures in the first place, but I prefer this way and besides, this is a flaw in the syntax highlighting as this syntax is clearly allowed and function is not treated as an identifier, unlike the syntax YAML file specifying: {{identifier}}.

Thank you, monad.

0 Likes

#2

From the looks of things this has been fixed in the latest version of the syntax. You could potentially use that version of the package until the next development release (making sure to revert at that point in case further enhancements are made).

Your code looks like this with the JavaScript package from build 3126:

It renders like this using the latest version of the syntax:

0 Likes

#3

Thank you! Works perfectly.

0 Likes