Skip to content

Commit 469d2d4

Browse files
mikeyhewrattrayalex
authored andcommitted
Parse Async Generators (#19)
1 parent 686ee48 commit 469d2d4

File tree

8 files changed

+338
-0
lines changed

8 files changed

+338
-0
lines changed

src/plugins/lightscript.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ pp.parseArrowType = function (node) {
265265
case "=*>": case "-*>":
266266
node.generator = true;
267267
break;
268+
case "=*/>": case "-*/>":
269+
node.async = true;
270+
node.generator = true;
271+
break;
268272
case "-get>":
269273
// TODO: validate that it's in a method not a function
270274
if (!node.kind) this.unexpected(null, "Only methods can be getters.");

src/tokenizer/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,14 @@ export default class Tokenizer {
401401
return this.finishToken(tt.arrow, "-*>");
402402
}
403403

404+
if (this.hasPlugin("asyncGenerators")) {
405+
const next3 = this.input.charCodeAt(this.state.pos + 3);
406+
if (next === 42 && next2 === 47 && next3 === 62) {
407+
this.state.pos += 4;
408+
return this.finishToken(tt.arrow, "-*/>");
409+
}
410+
}
411+
404412
let getOrSet;
405413
if (next === 103) getOrSet = "get";
406414
if (next === 115) getOrSet = "set";
@@ -478,6 +486,14 @@ export default class Tokenizer {
478486
this.state.pos += 3;
479487
return this.finishToken(tt.arrow, "=*>");
480488
}
489+
490+
if (this.hasPlugin("asyncGenerators")) {
491+
const next3 = this.input.charCodeAt(this.state.pos + 3);
492+
if (next === 42 && next2 === 47 && next3 === 62) {
493+
this.state.pos += 4;
494+
return this.finishToken(tt.arrow, "=*/>");
495+
}
496+
}
481497
}
482498

483499
if (code === 61 && next === 62) { // '=>'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fn() =*/>
2+
yield await x
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
{
2+
"type": "File",
3+
"start": 0,
4+
"end": 25,
5+
"loc": {
6+
"start": {
7+
"line": 1,
8+
"column": 0
9+
},
10+
"end": {
11+
"line": 2,
12+
"column": 15
13+
}
14+
},
15+
"program": {
16+
"type": "Program",
17+
"start": 0,
18+
"end": 25,
19+
"loc": {
20+
"start": {
21+
"line": 1,
22+
"column": 0
23+
},
24+
"end": {
25+
"line": 2,
26+
"column": 15
27+
}
28+
},
29+
"sourceType": "script",
30+
"body": [
31+
{
32+
"type": "NamedArrowDeclaration",
33+
"start": 0,
34+
"end": 25,
35+
"loc": {
36+
"start": {
37+
"line": 1,
38+
"column": 0
39+
},
40+
"end": {
41+
"line": 2,
42+
"column": 15
43+
}
44+
},
45+
"id": {
46+
"type": "Identifier",
47+
"start": 0,
48+
"end": 2,
49+
"loc": {
50+
"start": {
51+
"line": 1,
52+
"column": 0
53+
},
54+
"end": {
55+
"line": 1,
56+
"column": 2
57+
},
58+
"identifierName": "fn"
59+
},
60+
"name": "fn"
61+
},
62+
"generator": true,
63+
"expression": false,
64+
"async": true,
65+
"params": [],
66+
"skinny": false,
67+
"body": {
68+
"type": "BlockStatement",
69+
"start": 5,
70+
"end": 25,
71+
"loc": {
72+
"start": {
73+
"line": 1,
74+
"column": 5
75+
},
76+
"end": {
77+
"line": 2,
78+
"column": 15
79+
}
80+
},
81+
"body": [
82+
{
83+
"type": "ExpressionStatement",
84+
"start": 12,
85+
"end": 25,
86+
"loc": {
87+
"start": {
88+
"line": 2,
89+
"column": 2
90+
},
91+
"end": {
92+
"line": 2,
93+
"column": 15
94+
}
95+
},
96+
"expression": {
97+
"type": "YieldExpression",
98+
"start": 12,
99+
"end": 25,
100+
"loc": {
101+
"start": {
102+
"line": 2,
103+
"column": 2
104+
},
105+
"end": {
106+
"line": 2,
107+
"column": 15
108+
}
109+
},
110+
"argument": {
111+
"type": "AwaitExpression",
112+
"start": 18,
113+
"end": 25,
114+
"loc": {
115+
"start": {
116+
"line": 2,
117+
"column": 8
118+
},
119+
"end": {
120+
"line": 2,
121+
"column": 15
122+
}
123+
},
124+
"argument": {
125+
"type": "Identifier",
126+
"start": 24,
127+
"end": 25,
128+
"loc": {
129+
"start": {
130+
"line": 2,
131+
"column": 14
132+
},
133+
"end": {
134+
"line": 2,
135+
"column": 15
136+
},
137+
"identifierName": "x"
138+
},
139+
"name": "x"
140+
}
141+
}
142+
}
143+
}
144+
],
145+
"directives": [],
146+
"extra": {
147+
"curly": false
148+
}
149+
}
150+
}
151+
],
152+
"directives": []
153+
}
154+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["lightscript", "jsx", "flow", "asyncGenerators"]
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fn() -*/>
2+
yield await x
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
{
2+
"type": "File",
3+
"start": 0,
4+
"end": 25,
5+
"loc": {
6+
"start": {
7+
"line": 1,
8+
"column": 0
9+
},
10+
"end": {
11+
"line": 2,
12+
"column": 15
13+
}
14+
},
15+
"program": {
16+
"type": "Program",
17+
"start": 0,
18+
"end": 25,
19+
"loc": {
20+
"start": {
21+
"line": 1,
22+
"column": 0
23+
},
24+
"end": {
25+
"line": 2,
26+
"column": 15
27+
}
28+
},
29+
"sourceType": "script",
30+
"body": [
31+
{
32+
"type": "NamedArrowDeclaration",
33+
"start": 0,
34+
"end": 25,
35+
"loc": {
36+
"start": {
37+
"line": 1,
38+
"column": 0
39+
},
40+
"end": {
41+
"line": 2,
42+
"column": 15
43+
}
44+
},
45+
"id": {
46+
"type": "Identifier",
47+
"start": 0,
48+
"end": 2,
49+
"loc": {
50+
"start": {
51+
"line": 1,
52+
"column": 0
53+
},
54+
"end": {
55+
"line": 1,
56+
"column": 2
57+
},
58+
"identifierName": "fn"
59+
},
60+
"name": "fn"
61+
},
62+
"generator": true,
63+
"expression": false,
64+
"async": true,
65+
"params": [],
66+
"skinny": true,
67+
"body": {
68+
"type": "BlockStatement",
69+
"start": 5,
70+
"end": 25,
71+
"loc": {
72+
"start": {
73+
"line": 1,
74+
"column": 5
75+
},
76+
"end": {
77+
"line": 2,
78+
"column": 15
79+
}
80+
},
81+
"body": [
82+
{
83+
"type": "ExpressionStatement",
84+
"start": 12,
85+
"end": 25,
86+
"loc": {
87+
"start": {
88+
"line": 2,
89+
"column": 2
90+
},
91+
"end": {
92+
"line": 2,
93+
"column": 15
94+
}
95+
},
96+
"expression": {
97+
"type": "YieldExpression",
98+
"start": 12,
99+
"end": 25,
100+
"loc": {
101+
"start": {
102+
"line": 2,
103+
"column": 2
104+
},
105+
"end": {
106+
"line": 2,
107+
"column": 15
108+
}
109+
},
110+
"argument": {
111+
"type": "AwaitExpression",
112+
"start": 18,
113+
"end": 25,
114+
"loc": {
115+
"start": {
116+
"line": 2,
117+
"column": 8
118+
},
119+
"end": {
120+
"line": 2,
121+
"column": 15
122+
}
123+
},
124+
"argument": {
125+
"type": "Identifier",
126+
"start": 24,
127+
"end": 25,
128+
"loc": {
129+
"start": {
130+
"line": 2,
131+
"column": 14
132+
},
133+
"end": {
134+
"line": 2,
135+
"column": 15
136+
},
137+
"identifierName": "x"
138+
},
139+
"name": "x"
140+
}
141+
}
142+
}
143+
}
144+
],
145+
"directives": [],
146+
"extra": {
147+
"curly": false
148+
}
149+
}
150+
}
151+
],
152+
"directives": []
153+
}
154+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["lightscript", "jsx", "flow", "asyncGenerators"]
3+
}

0 commit comments

Comments
 (0)