-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed an issue with top-level for-await loops not being allowed with …
…`--module preserve` (#59042)
- Loading branch information
Showing
7 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/modulePreserveTopLevelAwait1(target=es2016).errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
modulePreserveTopLevelAwait1.ts(1,5): error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher. | ||
modulePreserveTopLevelAwait1.ts(2,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher. | ||
|
||
|
||
==== modulePreserveTopLevelAwait1.ts (2 errors) ==== | ||
for await (const x of []) {} | ||
~~~~~ | ||
!!! error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher. | ||
await Promise.resolve(); | ||
~~~~~ | ||
!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher. | ||
|
||
export {}; | ||
|
13 changes: 13 additions & 0 deletions
13
tests/baselines/reference/modulePreserveTopLevelAwait1(target=es2016).symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//// [tests/cases/compiler/modulePreserveTopLevelAwait1.ts] //// | ||
|
||
=== modulePreserveTopLevelAwait1.ts === | ||
for await (const x of []) {} | ||
>x : Symbol(x, Decl(modulePreserveTopLevelAwait1.ts, 0, 16)) | ||
|
||
await Promise.resolve(); | ||
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) | ||
>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, --, --)) | ||
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) | ||
|
||
export {}; | ||
|
23 changes: 23 additions & 0 deletions
23
tests/baselines/reference/modulePreserveTopLevelAwait1(target=es2016).types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//// [tests/cases/compiler/modulePreserveTopLevelAwait1.ts] //// | ||
|
||
=== modulePreserveTopLevelAwait1.ts === | ||
for await (const x of []) {} | ||
>x : any | ||
> : ^^^ | ||
>[] : undefined[] | ||
> : ^^^^^^^^^^^ | ||
|
||
await Promise.resolve(); | ||
>await Promise.resolve() : void | ||
> : ^^^^ | ||
>Promise.resolve() : Promise<void> | ||
> : ^^^^^^^^^^^^^ | ||
>Promise.resolve : { (): Promise<void>; <T>(value: T): Promise<Awaited<T>>; <T>(value: T | PromiseLike<T>): Promise<Awaited<T>>; } | ||
> : ^^^^^^ ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^ ^^^ ^^^ | ||
>Promise : PromiseConstructor | ||
> : ^^^^^^^^^^^^^^^^^^ | ||
>resolve : { (): Promise<void>; <T>(value: T): Promise<Awaited<T>>; <T>(value: T | PromiseLike<T>): Promise<Awaited<T>>; } | ||
> : ^^^^^^ ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^ ^^^ ^^^ | ||
|
||
export {}; | ||
|
13 changes: 13 additions & 0 deletions
13
tests/baselines/reference/modulePreserveTopLevelAwait1(target=esnext).symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//// [tests/cases/compiler/modulePreserveTopLevelAwait1.ts] //// | ||
|
||
=== modulePreserveTopLevelAwait1.ts === | ||
for await (const x of []) {} | ||
>x : Symbol(x, Decl(modulePreserveTopLevelAwait1.ts, 0, 16)) | ||
|
||
await Promise.resolve(); | ||
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) | ||
>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, --, --)) | ||
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) | ||
|
||
export {}; | ||
|
22 changes: 22 additions & 0 deletions
22
tests/baselines/reference/modulePreserveTopLevelAwait1(target=esnext).types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//// [tests/cases/compiler/modulePreserveTopLevelAwait1.ts] //// | ||
|
||
=== modulePreserveTopLevelAwait1.ts === | ||
for await (const x of []) {} | ||
>x : any | ||
>[] : undefined[] | ||
> : ^^^^^^^^^^^ | ||
|
||
await Promise.resolve(); | ||
>await Promise.resolve() : void | ||
> : ^^^^ | ||
>Promise.resolve() : Promise<void> | ||
> : ^^^^^^^^^^^^^ | ||
>Promise.resolve : { (): Promise<void>; <T>(value: T): Promise<Awaited<T>>; <T>(value: T | PromiseLike<T>): Promise<Awaited<T>>; } | ||
> : ^^^^^^ ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^ ^^^ ^^^ | ||
>Promise : PromiseConstructor | ||
> : ^^^^^^^^^^^^^^^^^^ | ||
>resolve : { (): Promise<void>; <T>(value: T): Promise<Awaited<T>>; <T>(value: T | PromiseLike<T>): Promise<Awaited<T>>; } | ||
> : ^^^^^^ ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^ ^^^ ^^^ | ||
|
||
export {}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @module: preserve | ||
// @target: es2016, esnext | ||
// @noEmit: true | ||
|
||
for await (const x of []) {} | ||
await Promise.resolve(); | ||
|
||
export {}; |