Skip to content

Commit 2e91e07

Browse files
committed
[javascript mode] Only tokenize operators that actually exist
To avoid bad parses when unary and binary operators are squashed together without spaces. Issue codemirror#5013
1 parent f18d202 commit 2e91e07

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

mode/javascript/javascript.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
128128
stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/);
129129
return ret("regexp", "string-2");
130130
} else {
131-
stream.eatWhile(isOperatorChar);
131+
stream.eat("=");
132132
return ret("operator", "operator", stream.current());
133133
}
134134
} else if (ch == "`") {
@@ -138,8 +138,13 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
138138
stream.skipToEnd();
139139
return ret("error", "error");
140140
} else if (isOperatorChar.test(ch)) {
141-
if (ch != ">" || !state.lexical || state.lexical.type != ">")
142-
stream.eatWhile(isOperatorChar);
141+
if (ch != ">" || !state.lexical || state.lexical.type != ">") {
142+
if (stream.eat("=")) {
143+
if (ch == "!" || ch == "=") stream.eat("=")
144+
} else if (ch == "<" || ch == ">" || ch == "*") {
145+
stream.eatWhile(ch);
146+
}
147+
}
143148
return ret("operator", "operator", stream.current());
144149
} else if (wordRE.test(ch)) {
145150
stream.eatWhile(wordRE);

0 commit comments

Comments
 (0)