-
Notifications
You must be signed in to change notification settings - Fork 12.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
disallow 'await' and 'yield' in property and enum member initializer (#…
…34892) * disallow 'await' and 'yield' in property and enum member initializer * accept baseline changes * Add a test for #34887 Ensures that this fixes #34887
- Loading branch information
Showing
21 changed files
with
285 additions
and
91 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
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
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,15 @@ | ||
tests/cases/conformance/enums/awaitAndYield.ts(3,15): error TS1308: 'await' expression is only allowed within an async function. | ||
tests/cases/conformance/enums/awaitAndYield.ts(4,15): error TS1163: A 'yield' expression is only allowed in a generator body. | ||
|
||
|
||
==== tests/cases/conformance/enums/awaitAndYield.ts (2 errors) ==== | ||
async function* test(x: Promise<number>) { | ||
enum E { | ||
foo = await x, | ||
~~~~~ | ||
!!! error TS1308: 'await' expression is only allowed within an async function. | ||
baz = yield 1, | ||
~~~~~ | ||
!!! error TS1163: A 'yield' expression is only allowed in a generator body. | ||
} | ||
} |
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,16 @@ | ||
//// [awaitAndYield.ts] | ||
async function* test(x: Promise<number>) { | ||
enum E { | ||
foo = await x, | ||
baz = yield 1, | ||
} | ||
} | ||
|
||
//// [awaitAndYield.js] | ||
async function* test(x) { | ||
let E; | ||
(function (E) { | ||
E[E["foo"] = await x] = "foo"; | ||
E[E["baz"] = yield 1] = "baz"; | ||
})(E || (E = {})); | ||
} |
68 changes: 68 additions & 0 deletions
68
tests/baselines/reference/awaitAndYieldInProperty.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,68 @@ | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(3,9): error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(3,21): error TS1308: 'await' expression is only allowed within an async function. | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(4,16): error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(4,28): error TS1308: 'await' expression is only allowed within an async function. | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(6,9): error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(6,21): error TS1163: A 'yield' expression is only allowed in a generator body. | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(7,16): error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(7,28): error TS1163: A 'yield' expression is only allowed in a generator body. | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(11,9): error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(11,21): error TS1308: 'await' expression is only allowed within an async function. | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(12,16): error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(12,28): error TS1308: 'await' expression is only allowed within an async function. | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(14,9): error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(14,21): error TS1163: A 'yield' expression is only allowed in a generator body. | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(15,16): error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
tests/cases/conformance/classes/awaitAndYieldInProperty.ts(15,28): error TS1163: A 'yield' expression is only allowed in a generator body. | ||
|
||
|
||
==== tests/cases/conformance/classes/awaitAndYieldInProperty.ts (16 errors) ==== | ||
async function* test(x: Promise<string>) { | ||
class C { | ||
[await x] = await x; | ||
~~~~~~~~~ | ||
!!! error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
~~~~~ | ||
!!! error TS1308: 'await' expression is only allowed within an async function. | ||
static [await x] = await x; | ||
~~~~~~~~~ | ||
!!! error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
~~~~~ | ||
!!! error TS1308: 'await' expression is only allowed within an async function. | ||
|
||
[yield 1] = yield 2; | ||
~~~~~~~~~ | ||
!!! error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
~~~~~ | ||
!!! error TS1163: A 'yield' expression is only allowed in a generator body. | ||
static [yield 3] = yield 4; | ||
~~~~~~~~~ | ||
!!! error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
~~~~~ | ||
!!! error TS1163: A 'yield' expression is only allowed in a generator body. | ||
} | ||
|
||
return class { | ||
[await x] = await x; | ||
~~~~~~~~~ | ||
!!! error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
~~~~~ | ||
!!! error TS1308: 'await' expression is only allowed within an async function. | ||
static [await x] = await x; | ||
~~~~~~~~~ | ||
!!! error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
~~~~~ | ||
!!! error TS1308: 'await' expression is only allowed within an async function. | ||
|
||
[yield 1] = yield 2; | ||
~~~~~~~~~ | ||
!!! error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
~~~~~ | ||
!!! error TS1163: A 'yield' expression is only allowed in a generator body. | ||
static [yield 3] = yield 4; | ||
~~~~~~~~~ | ||
!!! error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type. | ||
~~~~~ | ||
!!! error TS1163: A 'yield' expression is only allowed in a generator body. | ||
} | ||
} |
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,45 @@ | ||
//// [awaitAndYieldInProperty.ts] | ||
async function* test(x: Promise<string>) { | ||
class C { | ||
[await x] = await x; | ||
static [await x] = await x; | ||
|
||
[yield 1] = yield 2; | ||
static [yield 3] = yield 4; | ||
} | ||
|
||
return class { | ||
[await x] = await x; | ||
static [await x] = await x; | ||
|
||
[yield 1] = yield 2; | ||
static [yield 3] = yield 4; | ||
} | ||
} | ||
|
||
//// [awaitAndYieldInProperty.js] | ||
async function* test(x) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j; | ||
class C { | ||
constructor() { | ||
this[_a] = await x; | ||
this[_c] = yield 2; | ||
} | ||
} | ||
_a = await x, _b = await x, _c = yield 1, _d = yield 3; | ||
C[_b] = await x; | ||
C[_d] = yield 4; | ||
return _j = class { | ||
constructor() { | ||
this[_e] = await x; | ||
this[_g] = yield 2; | ||
} | ||
}, | ||
_e = await x, | ||
_f = await x, | ||
_g = yield 1, | ||
_h = yield 3, | ||
_j[_f] = await x, | ||
_j[_h] = yield 4, | ||
_j; | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/awaitInClassInAsyncFunction.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,18 @@ | ||
tests/cases/compiler/awaitInClassInAsyncFunction.ts(9,15): error TS1308: 'await' expression is only allowed within an async function. | ||
|
||
|
||
==== tests/cases/compiler/awaitInClassInAsyncFunction.ts (1 errors) ==== | ||
// https://github.com/microsoft/TypeScript/issues/34887 | ||
|
||
async function bar() { | ||
return 2; | ||
} | ||
|
||
async function foo() { | ||
return new class { | ||
baz = await bar(); | ||
~~~~~ | ||
!!! error TS1308: 'await' expression is only allowed within an async function. | ||
}; | ||
} | ||
|
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,26 @@ | ||
//// [awaitInClassInAsyncFunction.ts] | ||
// https://github.com/microsoft/TypeScript/issues/34887 | ||
|
||
async function bar() { | ||
return 2; | ||
} | ||
|
||
async function foo() { | ||
return new class { | ||
baz = await bar(); | ||
}; | ||
} | ||
|
||
|
||
//// [awaitInClassInAsyncFunction.js] | ||
// https://github.com/microsoft/TypeScript/issues/34887 | ||
async function bar() { | ||
return 2; | ||
} | ||
async function foo() { | ||
return new class { | ||
constructor() { | ||
this.baz = await bar(); | ||
} | ||
}; | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/baselines/reference/awaitInClassInAsyncFunction.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,20 @@ | ||
=== tests/cases/compiler/awaitInClassInAsyncFunction.ts === | ||
// https://github.com/microsoft/TypeScript/issues/34887 | ||
|
||
async function bar() { | ||
>bar : Symbol(bar, Decl(awaitInClassInAsyncFunction.ts, 0, 0)) | ||
|
||
return 2; | ||
} | ||
|
||
async function foo() { | ||
>foo : Symbol(foo, Decl(awaitInClassInAsyncFunction.ts, 4, 1)) | ||
|
||
return new class { | ||
baz = await bar(); | ||
>baz : Symbol((Anonymous class).baz, Decl(awaitInClassInAsyncFunction.ts, 7, 22)) | ||
>bar : Symbol(bar, Decl(awaitInClassInAsyncFunction.ts, 0, 0)) | ||
|
||
}; | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
tests/baselines/reference/awaitInClassInAsyncFunction.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,26 @@ | ||
=== tests/cases/compiler/awaitInClassInAsyncFunction.ts === | ||
// https://github.com/microsoft/TypeScript/issues/34887 | ||
|
||
async function bar() { | ||
>bar : () => Promise<number> | ||
|
||
return 2; | ||
>2 : 2 | ||
} | ||
|
||
async function foo() { | ||
>foo : () => Promise<(Anonymous class)> | ||
|
||
return new class { | ||
>new class { baz = await bar(); } : (Anonymous class) | ||
>class { baz = await bar(); } : typeof (Anonymous class) | ||
|
||
baz = await bar(); | ||
>baz : number | ||
>await bar() : number | ||
>bar() : Promise<number> | ||
>bar : () => Promise<number> | ||
|
||
}; | ||
} | ||
|
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.