Skip to content

Commit 9d96a89

Browse files
committed
[javascript mode] Make tokenizing of async more context-sensitive
Closes codemirror#4774
1 parent 54ec95a commit 9d96a89

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

mode/javascript/javascript.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
4141
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
4242
"this": kw("this"), "class": kw("class"), "super": kw("atom"),
4343
"yield": C, "export": kw("export"), "import": kw("import"), "extends": C,
44-
"await": C, "async": kw("async")
44+
"await": C
4545
};
4646

4747
// Extend the 'normal' keywords with the TypeScript language extensions
@@ -147,9 +147,16 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
147147
return ret("operator", "operator", stream.current());
148148
} else if (wordRE.test(ch)) {
149149
stream.eatWhile(wordRE);
150-
var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
151-
return (known && state.lastType != ".") ? ret(known.type, known.style, word) :
152-
ret("variable", "variable", word);
150+
var word = stream.current()
151+
if (state.lastType != ".") {
152+
if (keywords.propertyIsEnumerable(word)) {
153+
var kw = keywords[word]
154+
return ret(kw.type, kw.style, word)
155+
}
156+
if (word == "async" && stream.match(/^\s*[\(\w]/, false))
157+
return ret("async", "keyword", word)
158+
}
159+
return ret("variable", "variable", word)
153160
}
154161
}
155162

mode/javascript/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@
226226
" [property method]: [string 'GET']",
227227
"});");
228228

229+
MT("async_variable",
230+
"[keyword const] [def async] [operator =] {[property a]: [number 1]};",
231+
"[keyword const] [def foo] [operator =] [string-2 `bar ${][variable async].[property a][string-2 }`];")
232+
229233
MT("indent_switch",
230234
"[keyword switch] ([variable x]) {",
231235
" [keyword default]:",

0 commit comments

Comments
 (0)