Skip to content

Commit ab8bf8e

Browse files
tmcwadrianheine
authored andcommitted
Support for await syntax in JavaScript mode
[asynchronous iteration](http://2ality.com/2016/10/asynchronous-iteration.html) is a stage 4 ("finished") feature in ES2018, and its additional syntax - for await loops - don't require too much change in CodeMirror's JavaScript mode for support.
1 parent 236b40f commit ab8bf8e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

mode/javascript/javascript.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
638638
function maybeelse(type, value) {
639639
if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
640640
}
641-
function forspec(type) {
641+
function forspec(type, value) {
642+
if (value == "await") return cont(forspec);
642643
if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
643644
}
644645
function forspec1(type) {

mode/javascript/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@
7777
MT("for/of",
7878
"[keyword for]([keyword let] [def of] [keyword of] [variable something]) {}");
7979

80+
MT("for await",
81+
"[keyword for] [keyword await]([keyword let] [def of] [keyword of] [variable something]) {}");
82+
8083
MT("generator",
8184
"[keyword function*] [def repeat]([def n]) {",
8285
" [keyword for]([keyword var] [def i] [operator =] [number 0]; [variable-2 i] [operator <] [variable-2 n]; [operator ++][variable-2 i])",

0 commit comments

Comments
 (0)