Skip to content

Commit

Permalink
[javascript mode] fix tokenizing of underscore properties
Browse files Browse the repository at this point in the history
The regexp for parsing numbers with numeric separators is too
broad. This way, we mistake properties starting with underscore
to be numbers.
  • Loading branch information
hashseed authored and marijnh committed Jul 19, 2019
1 parent 1745746 commit 463ea2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mode/javascript/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
if (ch == '"' || ch == "'") {
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
} else if (ch == "." && stream.match(/^[\d_]+(?:[eE][+\-]?[\d_]+)?/)) {
} else if (ch == "." && stream.match(/^\d[\d_]*(?:[eE][+\-]?[\d_]+)?/)) {
return ret("number", "number");
} else if (ch == "." && stream.match("..")) {
return ret("spread", "meta");
Expand Down
7 changes: 7 additions & 0 deletions mode/javascript/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@
"[number 1E+123_456];",
"[number 12_34_56n];")

MT("underscore property",
"[variable something].[property _property];",
"[variable something].[property _123];",
"[variable something].[property _for];",
"[variable _for];",
"[variable _123];")

var ts_mode = CodeMirror.getMode({indentUnit: 2}, "application/typescript")
function TS(name) {
test.mode(name, ts_mode, Array.prototype.slice.call(arguments, 1))
Expand Down

0 comments on commit 463ea2c

Please sign in to comment.