Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e311620

Browse files
soda0289JamesHenry
authored andcommittedMay 1, 2017
Fix: Set await property on async iterators (for await) (fixes #236) (#239)
1 parent a294afa commit e311620

File tree

3 files changed

+506
-1
lines changed

3 files changed

+506
-1
lines changed
 

‎lib/ast-converter.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,11 +899,15 @@ module.exports = function(ast, extra) {
899899

900900
case SyntaxKind.ForInStatement:
901901
case SyntaxKind.ForOfStatement:
902+
var isAwait = node.awaitModifier
903+
&& node.awaitModifier.kind === ts.SyntaxKind.AwaitKeyword;
904+
902905
assign(result, {
903906
type: SyntaxKind[node.kind],
904907
left: convertChild(node.initializer),
905908
right: convertChild(node.expression),
906-
body: convertChild(node.statement)
909+
body: convertChild(node.statement),
910+
await: isAwait
907911
});
908912
break;
909913

Lines changed: 496 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,496 @@
1+
module.exports = {
2+
"type": "Program",
3+
"range": [
4+
0,
5+
69
6+
],
7+
"loc": {
8+
"start": {
9+
"line": 1,
10+
"column": 0
11+
},
12+
"end": {
13+
"line": 5,
14+
"column": 1
15+
}
16+
},
17+
"body": [
18+
{
19+
"type": "FunctionDeclaration",
20+
"range": [
21+
0,
22+
69
23+
],
24+
"loc": {
25+
"start": {
26+
"line": 1,
27+
"column": 0
28+
},
29+
"end": {
30+
"line": 5,
31+
"column": 1
32+
}
33+
},
34+
"id": {
35+
"type": "Identifier",
36+
"range": [
37+
15,
38+
18
39+
],
40+
"loc": {
41+
"start": {
42+
"line": 1,
43+
"column": 15
44+
},
45+
"end": {
46+
"line": 1,
47+
"column": 18
48+
}
49+
},
50+
"name": "foo"
51+
},
52+
"generator": false,
53+
"expression": false,
54+
"async": true,
55+
"params": [],
56+
"body": {
57+
"type": "BlockStatement",
58+
"range": [
59+
21,
60+
69
61+
],
62+
"loc": {
63+
"start": {
64+
"line": 1,
65+
"column": 21
66+
},
67+
"end": {
68+
"line": 5,
69+
"column": 1
70+
}
71+
},
72+
"body": [
73+
{
74+
"type": "ForOfStatement",
75+
"range": [
76+
27,
77+
67
78+
],
79+
"loc": {
80+
"start": {
81+
"line": 2,
82+
"column": 4
83+
},
84+
"end": {
85+
"line": 4,
86+
"column": 5
87+
}
88+
},
89+
"left": {
90+
"type": "VariableDeclaration",
91+
"range": [
92+
38,
93+
48
94+
],
95+
"loc": {
96+
"start": {
97+
"line": 2,
98+
"column": 15
99+
},
100+
"end": {
101+
"line": 2,
102+
"column": 25
103+
}
104+
},
105+
"declarations": [
106+
{
107+
"type": "VariableDeclarator",
108+
"range": [
109+
44,
110+
48
111+
],
112+
"loc": {
113+
"start": {
114+
"line": 2,
115+
"column": 21
116+
},
117+
"end": {
118+
"line": 2,
119+
"column": 25
120+
}
121+
},
122+
"id": {
123+
"type": "Identifier",
124+
"range": [
125+
44,
126+
48
127+
],
128+
"loc": {
129+
"start": {
130+
"line": 2,
131+
"column": 21
132+
},
133+
"end": {
134+
"line": 2,
135+
"column": 25
136+
}
137+
},
138+
"name": "item"
139+
},
140+
"init": null
141+
}
142+
],
143+
"kind": "const"
144+
},
145+
"right": {
146+
"type": "Identifier",
147+
"range": [
148+
52,
149+
57
150+
],
151+
"loc": {
152+
"start": {
153+
"line": 2,
154+
"column": 29
155+
},
156+
"end": {
157+
"line": 2,
158+
"column": 34
159+
}
160+
},
161+
"name": "items"
162+
},
163+
"body": {
164+
"type": "BlockStatement",
165+
"range": [
166+
59,
167+
67
168+
],
169+
"loc": {
170+
"start": {
171+
"line": 2,
172+
"column": 36
173+
},
174+
"end": {
175+
"line": 4,
176+
"column": 5
177+
}
178+
},
179+
"body": []
180+
},
181+
"await": true
182+
}
183+
]
184+
}
185+
}
186+
],
187+
"sourceType": "script",
188+
"tokens": [
189+
{
190+
"type": "Identifier",
191+
"value": "async",
192+
"range": [
193+
0,
194+
5
195+
],
196+
"loc": {
197+
"start": {
198+
"line": 1,
199+
"column": 0
200+
},
201+
"end": {
202+
"line": 1,
203+
"column": 5
204+
}
205+
}
206+
},
207+
{
208+
"type": "Keyword",
209+
"value": "function",
210+
"range": [
211+
6,
212+
14
213+
],
214+
"loc": {
215+
"start": {
216+
"line": 1,
217+
"column": 6
218+
},
219+
"end": {
220+
"line": 1,
221+
"column": 14
222+
}
223+
}
224+
},
225+
{
226+
"type": "Identifier",
227+
"value": "foo",
228+
"range": [
229+
15,
230+
18
231+
],
232+
"loc": {
233+
"start": {
234+
"line": 1,
235+
"column": 15
236+
},
237+
"end": {
238+
"line": 1,
239+
"column": 18
240+
}
241+
}
242+
},
243+
{
244+
"type": "Punctuator",
245+
"value": "(",
246+
"range": [
247+
18,
248+
19
249+
],
250+
"loc": {
251+
"start": {
252+
"line": 1,
253+
"column": 18
254+
},
255+
"end": {
256+
"line": 1,
257+
"column": 19
258+
}
259+
}
260+
},
261+
{
262+
"type": "Punctuator",
263+
"value": ")",
264+
"range": [
265+
19,
266+
20
267+
],
268+
"loc": {
269+
"start": {
270+
"line": 1,
271+
"column": 19
272+
},
273+
"end": {
274+
"line": 1,
275+
"column": 20
276+
}
277+
}
278+
},
279+
{
280+
"type": "Punctuator",
281+
"value": "{",
282+
"range": [
283+
21,
284+
22
285+
],
286+
"loc": {
287+
"start": {
288+
"line": 1,
289+
"column": 21
290+
},
291+
"end": {
292+
"line": 1,
293+
"column": 22
294+
}
295+
}
296+
},
297+
{
298+
"type": "Keyword",
299+
"value": "for",
300+
"range": [
301+
27,
302+
30
303+
],
304+
"loc": {
305+
"start": {
306+
"line": 2,
307+
"column": 4
308+
},
309+
"end": {
310+
"line": 2,
311+
"column": 7
312+
}
313+
}
314+
},
315+
{
316+
"type": "Identifier",
317+
"value": "await",
318+
"range": [
319+
31,
320+
36
321+
],
322+
"loc": {
323+
"start": {
324+
"line": 2,
325+
"column": 8
326+
},
327+
"end": {
328+
"line": 2,
329+
"column": 13
330+
}
331+
}
332+
},
333+
{
334+
"type": "Punctuator",
335+
"value": "(",
336+
"range": [
337+
37,
338+
38
339+
],
340+
"loc": {
341+
"start": {
342+
"line": 2,
343+
"column": 14
344+
},
345+
"end": {
346+
"line": 2,
347+
"column": 15
348+
}
349+
}
350+
},
351+
{
352+
"type": "Keyword",
353+
"value": "const",
354+
"range": [
355+
38,
356+
43
357+
],
358+
"loc": {
359+
"start": {
360+
"line": 2,
361+
"column": 15
362+
},
363+
"end": {
364+
"line": 2,
365+
"column": 20
366+
}
367+
}
368+
},
369+
{
370+
"type": "Identifier",
371+
"value": "item",
372+
"range": [
373+
44,
374+
48
375+
],
376+
"loc": {
377+
"start": {
378+
"line": 2,
379+
"column": 21
380+
},
381+
"end": {
382+
"line": 2,
383+
"column": 25
384+
}
385+
}
386+
},
387+
{
388+
"type": "Identifier",
389+
"value": "of",
390+
"range": [
391+
49,
392+
51
393+
],
394+
"loc": {
395+
"start": {
396+
"line": 2,
397+
"column": 26
398+
},
399+
"end": {
400+
"line": 2,
401+
"column": 28
402+
}
403+
}
404+
},
405+
{
406+
"type": "Identifier",
407+
"value": "items",
408+
"range": [
409+
52,
410+
57
411+
],
412+
"loc": {
413+
"start": {
414+
"line": 2,
415+
"column": 29
416+
},
417+
"end": {
418+
"line": 2,
419+
"column": 34
420+
}
421+
}
422+
},
423+
{
424+
"type": "Punctuator",
425+
"value": ")",
426+
"range": [
427+
57,
428+
58
429+
],
430+
"loc": {
431+
"start": {
432+
"line": 2,
433+
"column": 34
434+
},
435+
"end": {
436+
"line": 2,
437+
"column": 35
438+
}
439+
}
440+
},
441+
{
442+
"type": "Punctuator",
443+
"value": "{",
444+
"range": [
445+
59,
446+
60
447+
],
448+
"loc": {
449+
"start": {
450+
"line": 2,
451+
"column": 36
452+
},
453+
"end": {
454+
"line": 2,
455+
"column": 37
456+
}
457+
}
458+
},
459+
{
460+
"type": "Punctuator",
461+
"value": "}",
462+
"range": [
463+
66,
464+
67
465+
],
466+
"loc": {
467+
"start": {
468+
"line": 4,
469+
"column": 4
470+
},
471+
"end": {
472+
"line": 4,
473+
"column": 5
474+
}
475+
}
476+
},
477+
{
478+
"type": "Punctuator",
479+
"value": "}",
480+
"range": [
481+
68,
482+
69
483+
],
484+
"loc": {
485+
"start": {
486+
"line": 5,
487+
"column": 0
488+
},
489+
"end": {
490+
"line": 5,
491+
"column": 1
492+
}
493+
}
494+
}
495+
]
496+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
async function foo() {
2+
for await (const item of items) {
3+
4+
}
5+
}

0 commit comments

Comments
 (0)
This repository has been archived.