JavaScript lexer bugs & requests #1316
ct-martin
started this conversation in
^ Lexer Requests and Bugs
Replies: 1 comment
|
FWIW knowing Go is not a preqrequisite - the lexer definitions are XML files. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Is there an existing issue for this?
Describe the bug
Here's a hodgepodge of JavaScript lexer bugs & features. Apologies that I haven't done much with Go so I can't help with testing, but I'll try to include enough examples and/or regex changes for the XML to make this easier.
const&classare used for declarations but marked reservedWhile MDN lists these as reserved keywords, it also lists
let,var,function, etc. as reserved keywords. However, Chroma has the latter split out intoKeywordDeclarationso it would make more sense to putconst&classwithletandvarsince they're used for a similar purpose.as,from, &*should be keywords when used withimportNot sure how good of a way there is to do this in Chroma since this only applies when used with
import, but...consolebuiltin is missingStrictly speaking, it's not technically a built-in to JS itself as a language, but it is a built-in on both browsers and Node, and would be useful to treat as such. I can also see
NameBuiltinPseudoin a couple themes and I don't quite know what the difference between that andNameBuiltinare but it could be a better candidate for this.For example:
or:
or in TypeScript:
This won't catch all cases where they're used (and there isn't a good way to do that without analyzing every variable-like case), however, this would be an improvement even if it's just looking for preceding keywords.
NameOtherFor example:
This could be done adequately with the following regex lookahead:
While not perfect, I was playing around in VS Code to see what syntax it would consider a variable vs function name and it seems to follow a similar logic. I didn't manage to track down their lexer so I don't know if there are any other edge cases, but this seemed to work comparably.
A bunch of built-in type classes aren't on the list of builtins. While there's a lot of these and maybe not all are useful, there are common-enough ones like
BigIntas well as some useful-in-odd-cases ones likeUint8ClampedArray(if you ever end up working with pixel data from the Canvas API).https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
To Reproduce
Chroma Playground
VS Code (ignore different colors on punctuation):
I'm not sure if you'd consider this as saving time or not since I'm not familiar with Go (and would be doing this a bit in the blind), but I can try writing a PR (just editing the XML) if you'd like.
(And also, thanks for the great tool; it's saved me a good bit of hassle)
All reactions