JavaScript keywords in langs.model.xml
-
TL;DR
1. Remove old keywords
2. Move type related keywords from instruction word to type word
3. Add current standard built-in objects as types
4. Add most commonly used web apis as types
5. Remove document properties and methods from window instructions
6. Remove ambiguous properties, methods and events from window instructionsNote: Your copy of langs.xml (and other files in %appdata%) does not automatically update when there are changes to langs.model.xml. If you have been using and upgrading Notepad++ for a long time then your copy of these files may be missing a lot of updates.
.After doing a new install I noticed javascript files are highlighting words that it shouldn’t be. So I started cleaning up the keywords in my langs.xml file and am now at a point here I can share and discuss what should be in the default langs.model.xml file. I’ll create the github issue for the update at a later date.
There are currently three groups of keywords:
- Instruction word: instre1
- Type word: type1
- Window instruction: instre2
We should start by discussing what peoples understanding and expectation of each group is. The labels for the “instruction word” and “type word” groups came from the other c style languages. The “window instruction” group was added just for javascript. Embedded javascript just has a single “keyword” group.
The way I see it:
Instruction words are keywords.
Type words has a mixture of things. Most are global objects that you would use with new, extends, instanceof or have static methods. Some special words would also be in this group depending on your interpretation.
Window instructions are global functions and variables/properties.Instruction words
These are mostly keywords with the majority also being reserved words.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#keywordsMy first recommendation is to remove the ‘future reserved words in older standards’ keywords. These are no longer keywords and don’t need to be highlighted.
True, false, and null are reserved keywords but they are also type literals. I have moved them from instruction words to type words.
Prototype is not a keyword or instruction but does have special meaning. Since it was also already included in the type words I have removed it from here.
There are a few other words that would be nice to have highlighted in the correct context but the lexer can’t do that. These remain excluded from the list; as, from (import/export statements), get, set (object property getters/setters).
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#identifiers_with_special_meaningsType words
In addition to the type literals I have also added arguments since it is a special identifier in functions.The object prototype is another special case. I don’t think the methods on the prototype should be highlighted as types and they don’t really belong in the window instructions either. Some people probably want these highlighted so I’m not sure what to do with these.
I’ve added all the standard built-in objects with the exception of the function properties, which have been added to the window instructions, and most of the control abstraction objects, these are experimental or don’t have global objects.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_ObjectsThis does raise the question of where the isFinite and isNaN functions should be. Do they belong with the other global functions or are they a special case that belongs here because you need to use them when comparing types?
More types are available through the various Web APIs. This list is large and growing so my aim is to only include types that you commonly use with new, extends, instanceof or has static properties and methods.
https://developer.mozilla.org/en-US/docs/Web/APIWindow instructions
First I’ve removed all the document properties and other unknowns. These should never have been in this list and is what made me go down this rabbit hole.There are a large number of properties, methods and events on the window object, so I think there should be a distinction between global objects and functions vs window properties and methods. The globals are what you would commonly use without the window prefix. The others are either common names or ambiguous depending on context so shouldn’t need to be highlighted because you should have the window prefix (or self, globalThis). I’ve excluded some values that haven’t been implemented by all browsers. I haven’t finalised my own list for this section so there will probably be some debate about what to include.
https://developer.mozilla.org/en-US/docs/Web/API/WindowI’m also interested in hearing from any Node.js developers and what they would like to see.
A few changes for stylers.xml
javascript.js includes an option for verbatim strings (@" ") however js doesn’t support this. I think this was copied from the java style (or other c style language) and should be removed.
It also has the option CHARACTER which is single quoted strings. The three strings should be labelled DOUBLE, SINGLE and LITERAL. Looking at the other languages there doesn’t appear to be any consistency between if STRING is at the start or end of the label. I think string should be at the end to match html and css.Adding my list of keywords gets this post flagged as spam. I will see if I can find another way.
-
The default langs.model.xml
My langs.xml
-
If you want these kinds of changes implemented, your best bet is probably to submit a pull request.
-
@Mark-Olson Yes, that is my plan. At the moment I just want some feedback from the community on some of my suggested changes.