Skip to content

Commit 5a711e7

Browse files
hikarino-myelibarzilay
authored andcommitted
Add test cases for top level "for await of".
1 parent 1e3f239 commit 5a711e7

7 files changed

+71
-11
lines changed

tests/baselines/reference/awaitInNonAsyncFunction.errors.txt

+2-2
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

+12-6
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
~
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts(1,1): 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.
22
tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts(1,7): error TS2304: Cannot find name 'x'.
3+
tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts(5,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.
34

45

5-
==== tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts (2 errors) ====
6+
==== tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts (3 errors) ====
67
await x;
78
~~~~~
89
!!! 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.
910
~
1011
!!! error TS2304: Cannot find name 'x'.
12+
13+
const arr = [Promise.resolve()];
14+
15+
for await (const item of arr) {
16+
~~~~~
17+
!!! 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.
18+
item;
19+
}
1120

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
//// [topLevelAwaitNonModule.ts]
22
await x;
3+
4+
const arr = [Promise.resolve()];
5+
6+
for await (const item of arr) {
7+
item;
8+
}
39

410

511
//// [topLevelAwaitNonModule.js]
612
await x;
13+
const arr = [Promise.resolve()];
14+
for await (const item of arr) {
15+
item;
16+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
=== tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts ===
22
await x;
3-
No type information for this code.
4-
No type information for this code.
3+
4+
const arr = [Promise.resolve()];
5+
>arr : Symbol(arr, Decl(topLevelAwaitNonModule.ts, 2, 5))
6+
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
7+
>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, --, --), Decl(lib.es2018.promise.d.ts, --, --))
8+
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
9+
10+
for await (const item of arr) {
11+
>item : Symbol(item, Decl(topLevelAwaitNonModule.ts, 4, 16))
12+
>arr : Symbol(arr, Decl(topLevelAwaitNonModule.ts, 2, 5))
13+
14+
item;
15+
>item : Symbol(item, Decl(topLevelAwaitNonModule.ts, 4, 16))
16+
}
17+

tests/baselines/reference/topLevelAwaitNonModule.types

+16
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,19 @@ await x;
33
>await x : any
44
>x : any
55

6+
const arr = [Promise.resolve()];
7+
>arr : Promise<void>[]
8+
>[Promise.resolve()] : Promise<void>[]
9+
>Promise.resolve() : Promise<void>
10+
>Promise.resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
11+
>Promise : PromiseConstructor
12+
>resolve : { <T>(value: T | PromiseLike<T>): Promise<T>; (): Promise<void>; }
13+
14+
for await (const item of arr) {
15+
>item : void
16+
>arr : Promise<void>[]
17+
18+
item;
19+
>item : void
20+
}
21+
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
// @target: esnext
22
// @module: esnext
33
await x;
4+
5+
const arr = [Promise.resolve()];
6+
7+
for await (const item of arr) {
8+
item;
9+
}

0 commit comments

Comments
 (0)