Skip to content

Commit 9bb35c8

Browse files
committed
Add test cases for top level "for await of".
1 parent a718929 commit 9bb35c8

22 files changed

+329
-15
lines changed

tests/baselines/reference/awaitInNonAsyncFunction.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ tests/cases/compiler/awaitInNonAsyncFunction.ts(30,9): error TS1103: A 'for-awai
1212
tests/cases/compiler/awaitInNonAsyncFunction.ts(31,5): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
1313
tests/cases/compiler/awaitInNonAsyncFunction.ts(34,7): error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
1414
tests/cases/compiler/awaitInNonAsyncFunction.ts(35,5): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
15-
tests/cases/compiler/awaitInNonAsyncFunction.ts(39,5): error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
15+
tests/cases/compiler/awaitInNonAsyncFunction.ts(39,5): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
1616
tests/cases/compiler/awaitInNonAsyncFunction.ts(40,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
1717

1818

@@ -97,7 +97,7 @@ tests/cases/compiler/awaitInNonAsyncFunction.ts(40,1): error TS1378: Top-level '
9797

9898
for await (const _ of []);
9999
~~~~~
100-
!!! error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
100+
!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
101101
await null;
102102
~~~~~
103103
!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.

tests/baselines/reference/parser.forAwait.es2018.errors.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,30 @@ tests/cases/conformance/parser/ecmascript2018/forAwait/inFunctionDeclWithDeclIsE
77
tests/cases/conformance/parser/ecmascript2018/forAwait/inFunctionDeclWithExprIsError.ts(3,9): error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
88
tests/cases/conformance/parser/ecmascript2018/forAwait/inGeneratorWithDeclIsError.ts(3,9): error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
99
tests/cases/conformance/parser/ecmascript2018/forAwait/inGeneratorWithExprIsError.ts(3,9): error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
10-
tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts(1,5): error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
10+
tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts(1,5): error TS1375: 'await' expressions are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.
11+
tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts(1,5): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
1112
tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts(1,23): error TS2304: Cannot find name 'y'.
12-
tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,5): error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
13+
tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,5): error TS1375: 'await' expressions are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.
14+
tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,5): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
1315
tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,12): error TS2304: Cannot find name 'x'.
1416
tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,17): error TS2304: Cannot find name 'y'.
1517

1618

17-
==== tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts (2 errors) ====
19+
==== tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts (3 errors) ====
1820
for await (const x of y) {
1921
~~~~~
20-
!!! error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
22+
!!! error TS1375: 'await' expressions are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.
23+
~~~~~
24+
!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
2125
~
2226
!!! error TS2304: Cannot find name 'y'.
2327
}
24-
==== tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts (3 errors) ====
28+
==== tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts (4 errors) ====
2529
for await (x of y) {
2630
~~~~~
27-
!!! error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
31+
!!! error TS1375: 'await' expressions are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.
32+
~~~~~
33+
!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
2834
~
2935
!!! error TS2304: Cannot find name 'x'.
3036
~
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
tests/cases/conformance/externalModules/topLevelAwait.ts(2,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
2+
tests/cases/conformance/externalModules/topLevelAwait.ts(6,5): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
23

34

4-
==== tests/cases/conformance/externalModules/topLevelAwait.ts (1 errors) ====
5+
==== tests/cases/conformance/externalModules/topLevelAwait.ts (2 errors) ====
56
export const x = 1;
67
await x;
78
~~~~~
89
!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
10+
11+
const arr = [Promise.resolve()];
12+
13+
for await (const item of arr) {
14+
~~~~~
15+
!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
16+
item;
17+
}
918

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
11
//// [topLevelAwait.ts]
22
export const x = 1;
33
await x;
4+
5+
const arr = [Promise.resolve()];
6+
7+
for await (const item of arr) {
8+
item;
9+
}
410

511

612
//// [topLevelAwait.js]
13+
var __asyncValues = (this && this.__asyncValues) || function (o) {
14+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
15+
var m = o[Symbol.asyncIterator], i;
16+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
17+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
18+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
19+
};
20+
var e_1, _a;
721
export const x = 1;
822
await x;
23+
const arr = [Promise.resolve()];
24+
try {
25+
for (var arr_1 = __asyncValues(arr), arr_1_1; arr_1_1 = await arr_1.next(), !arr_1_1.done;) {
26+
const item = arr_1_1.value;
27+
item;
28+
}
29+
}
30+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
31+
finally {
32+
try {
33+
if (arr_1_1 && !arr_1_1.done && (_a = arr_1.return)) await _a.call(arr_1);
34+
}
35+
finally { if (e_1) throw e_1.error; }
36+
}

tests/baselines/reference/topLevelAwait(module=esnext,target=es2015).symbols

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,17 @@ export const x = 1;
55
await x;
66
>x : Symbol(x, Decl(topLevelAwait.ts, 0, 12))
77

8+
const arr = [Promise.resolve()];
9+
>arr : Symbol(arr, Decl(topLevelAwait.ts, 3, 5))
10+
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
11+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
12+
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
13+
14+
for await (const item of arr) {
15+
>item : Symbol(item, Decl(topLevelAwait.ts, 5, 16))
16+
>arr : Symbol(arr, Decl(topLevelAwait.ts, 3, 5))
17+
18+
item;
19+
>item : Symbol(item, Decl(topLevelAwait.ts, 5, 16))
20+
}
21+

tests/baselines/reference/topLevelAwait(module=esnext,target=es2015).types

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,19 @@ await x;
77
>await x : 1
88
>x : 1
99

10+
const arr = [Promise.resolve()];
11+
>arr : Promise<void>[]
12+
>[Promise.resolve()] : Promise<void>[]
13+
>Promise.resolve() : Promise<void>
14+
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
15+
>Promise : PromiseConstructor
16+
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
17+
18+
for await (const item of arr) {
19+
>item : void
20+
>arr : Promise<void>[]
21+
22+
item;
23+
>item : void
24+
}
25+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
11
//// [topLevelAwait.ts]
22
export const x = 1;
33
await x;
4+
5+
const arr = [Promise.resolve()];
6+
7+
for await (const item of arr) {
8+
item;
9+
}
410

511

612
//// [topLevelAwait.js]
13+
var __asyncValues = (this && this.__asyncValues) || function (o) {
14+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
15+
var m = o[Symbol.asyncIterator], i;
16+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
17+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
18+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
19+
};
20+
var e_1, _a;
721
export const x = 1;
822
await x;
23+
const arr = [Promise.resolve()];
24+
try {
25+
for (var arr_1 = __asyncValues(arr), arr_1_1; arr_1_1 = await arr_1.next(), !arr_1_1.done;) {
26+
const item = arr_1_1.value;
27+
item;
28+
}
29+
}
30+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
31+
finally {
32+
try {
33+
if (arr_1_1 && !arr_1_1.done && (_a = arr_1.return)) await _a.call(arr_1);
34+
}
35+
finally { if (e_1) throw e_1.error; }
36+
}

tests/baselines/reference/topLevelAwait(module=esnext,target=es2017).symbols

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,17 @@ export const x = 1;
55
await x;
66
>x : Symbol(x, Decl(topLevelAwait.ts, 0, 12))
77

8+
const arr = [Promise.resolve()];
9+
>arr : Symbol(arr, Decl(topLevelAwait.ts, 3, 5))
10+
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
11+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
12+
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
13+
14+
for await (const item of arr) {
15+
>item : Symbol(item, Decl(topLevelAwait.ts, 5, 16))
16+
>arr : Symbol(arr, Decl(topLevelAwait.ts, 3, 5))
17+
18+
item;
19+
>item : Symbol(item, Decl(topLevelAwait.ts, 5, 16))
20+
}
21+

tests/baselines/reference/topLevelAwait(module=esnext,target=es2017).types

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,19 @@ await x;
77
>await x : 1
88
>x : 1
99

10+
const arr = [Promise.resolve()];
11+
>arr : Promise<void>[]
12+
>[Promise.resolve()] : Promise<void>[]
13+
>Promise.resolve() : Promise<void>
14+
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
15+
>Promise : PromiseConstructor
16+
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
17+
18+
for await (const item of arr) {
19+
>item : void
20+
>arr : Promise<void>[]
21+
22+
item;
23+
>item : void
24+
}
25+
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
tests/cases/conformance/externalModules/topLevelAwait.ts(2,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
2+
tests/cases/conformance/externalModules/topLevelAwait.ts(6,5): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
23

34

4-
==== tests/cases/conformance/externalModules/topLevelAwait.ts (1 errors) ====
5+
==== tests/cases/conformance/externalModules/topLevelAwait.ts (2 errors) ====
56
export const x = 1;
67
await x;
78
~~~~~
89
!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
10+
11+
const arr = [Promise.resolve()];
12+
13+
for await (const item of arr) {
14+
~~~~~
15+
!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
16+
item;
17+
}
918

0 commit comments

Comments
 (0)