You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Support Top Level "for await of".
* Add test cases for top level "for await of".
* Apply suggestions from code review
* add test cases
* remove redundant variables
* fix test baselines
* Update diagnostic message and tests
Co-authored-by: Ron Buckton <[email protected]>
Copy file name to clipboardExpand all lines: src/compiler/diagnosticMessages.json
+10-1
Original file line number
Diff line number
Diff line change
@@ -307,7 +307,7 @@
307
307
"category": "Error",
308
308
"code": 1102
309
309
},
310
-
"A 'for-await-of' statement is only allowed within an async function or async generator.": {
310
+
"'forawait' loops are only allowed within async functions and at the top levels of modules.": {
311
311
"category": "Error",
312
312
"code": 1103
313
313
},
@@ -1352,6 +1352,15 @@
1352
1352
"category": "Message",
1353
1353
"code": 1430
1354
1354
},
1355
+
"'for await' loops 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.": {
1356
+
"category": "Error",
1357
+
"code": 1431
1358
+
},
1359
+
"Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.": {
1360
+
"category": "Error",
1361
+
"code": 1432
1362
+
},
1363
+
1355
1364
"The types of '{0}' are incompatible between these types.": {
Copy file name to clipboardExpand all lines: tests/baselines/reference/awaitInNonAsyncFunction.errors.txt
+16-16
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,18 @@
1
-
tests/cases/compiler/awaitInNonAsyncFunction.ts(4,7): error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
1
+
tests/cases/compiler/awaitInNonAsyncFunction.ts(4,7): error TS1103: 'forawait' loops are only allowed within async functions and at the top levels of modules.
2
2
tests/cases/compiler/awaitInNonAsyncFunction.ts(5,10): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
3
-
tests/cases/compiler/awaitInNonAsyncFunction.ts(9,7): error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
3
+
tests/cases/compiler/awaitInNonAsyncFunction.ts(9,7): error TS1103: 'forawait' loops are only allowed within async functions and at the top levels of modules.
4
4
tests/cases/compiler/awaitInNonAsyncFunction.ts(10,10): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
5
-
tests/cases/compiler/awaitInNonAsyncFunction.ts(14,7): error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
5
+
tests/cases/compiler/awaitInNonAsyncFunction.ts(14,7): error TS1103: 'forawait' loops are only allowed within async functions and at the top levels of modules.
6
6
tests/cases/compiler/awaitInNonAsyncFunction.ts(15,3): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
7
-
tests/cases/compiler/awaitInNonAsyncFunction.ts(19,7): error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
7
+
tests/cases/compiler/awaitInNonAsyncFunction.ts(19,7): error TS1103: 'forawait' loops are only allowed within async functions and at the top levels of modules.
8
8
tests/cases/compiler/awaitInNonAsyncFunction.ts(20,10): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
9
-
tests/cases/compiler/awaitInNonAsyncFunction.ts(24,7): error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
9
+
tests/cases/compiler/awaitInNonAsyncFunction.ts(24,7): error TS1103: 'forawait' loops are only allowed within async functions and at the top levels of modules.
10
10
tests/cases/compiler/awaitInNonAsyncFunction.ts(25,9): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
11
-
tests/cases/compiler/awaitInNonAsyncFunction.ts(30,9): error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
11
+
tests/cases/compiler/awaitInNonAsyncFunction.ts(30,9): error TS1103: 'forawait' loops are only allowed within async functions and at the top levels of modules.
12
12
tests/cases/compiler/awaitInNonAsyncFunction.ts(31,5): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
13
-
tests/cases/compiler/awaitInNonAsyncFunction.ts(34,7): error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
13
+
tests/cases/compiler/awaitInNonAsyncFunction.ts(34,7): error TS1103: 'forawait' loops are only allowed within async functions and at the top levels of modules.
14
14
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 TS1432: Top-level 'forawait' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
16
16
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.
!!! error TS1103: A 'for-await-of' statement is only allowed within an async function or async generator.
100
+
!!! error TS1432: Top-level 'forawait' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.
101
101
await null;
102
102
~~~~~
103
103
!!! 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.
0 commit comments