lezer-parser / javascript

A JavaScript lezer grammar

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Highlight global variables

NiedziolkaMichal opened this issue · comments

There are 4 global properties in JavaScript: undefined, NaN, Infinity & globalThis. All of those are unique in the language, they have special features and undefined is also a primitive value. Current highlight.js treats them as variableName, because of which they share color with any other variable. Would it be possible to put those 4 values under a unique tag, so they can have a different style than rest of the variables? Two of those: undefined & NaN could easily share tag with null.

Not really, because they can be shadowed (function(undefined) { return undefined + 1 }), so a parser that doesn't track scopes can't really distinguish them from regular variable names. As such, I've decided to not parse them specially.