Skip to content

Commit 4e6705c

Browse files
committed
Fixed a crash related to computed enum member keys
1 parent cdc205d commit 4e6705c

File tree

5 files changed

+93
-1
lines changed

5 files changed

+93
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13549,7 +13549,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1354913549
for (const declaration of symbol.declarations) {
1355013550
if (declaration.kind === SyntaxKind.EnumDeclaration) {
1355113551
for (const member of (declaration as EnumDeclaration).members) {
13552-
if (hasBindableName(member)) {
13552+
if (!hasDynamicName(member)) {
1355313553
const memberSymbol = getSymbolOfDeclaration(member);
1355413554
const value = getEnumMemberValue(member).value;
1355513555
const memberType = getFreshTypeOfLiteralType(
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
computedEnumMemberKeyNoCrash1.ts(4,5): error TS1164: Computed property names are not allowed in enums.
2+
3+
4+
==== computedEnumMemberKeyNoCrash1.ts (1 errors) ====
5+
// https://github.com/microsoft/TypeScript/issues/63173
6+
7+
declare const enum E {
8+
[foo] = 1,
9+
~~~~~
10+
!!! error TS1164: Computed property names are not allowed in enums.
11+
A,
12+
foo = 10,
13+
}
14+
E.A.toString();
15+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [tests/cases/compiler/computedEnumMemberKeyNoCrash1.ts] ////
2+
3+
=== computedEnumMemberKeyNoCrash1.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/63173
5+
6+
declare const enum E {
7+
>E : Symbol(E, Decl(computedEnumMemberKeyNoCrash1.ts, 0, 0))
8+
9+
[foo] = 1,
10+
>[foo] : Symbol(E[foo], Decl(computedEnumMemberKeyNoCrash1.ts, 2, 22))
11+
>foo : Symbol(E.foo, Decl(computedEnumMemberKeyNoCrash1.ts, 4, 6))
12+
13+
A,
14+
>A : Symbol(E.A, Decl(computedEnumMemberKeyNoCrash1.ts, 3, 14))
15+
16+
foo = 10,
17+
>foo : Symbol(E.foo, Decl(computedEnumMemberKeyNoCrash1.ts, 4, 6))
18+
}
19+
E.A.toString();
20+
>E.A.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))
21+
>E.A : Symbol(E.A, Decl(computedEnumMemberKeyNoCrash1.ts, 3, 14))
22+
>E : Symbol(E, Decl(computedEnumMemberKeyNoCrash1.ts, 0, 0))
23+
>A : Symbol(E.A, Decl(computedEnumMemberKeyNoCrash1.ts, 3, 14))
24+
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))
25+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//// [tests/cases/compiler/computedEnumMemberKeyNoCrash1.ts] ////
2+
3+
=== computedEnumMemberKeyNoCrash1.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/63173
5+
6+
declare const enum E {
7+
>E : E
8+
> : ^
9+
10+
[foo] = 1,
11+
>[foo] : E
12+
> : ^
13+
>foo : E.foo
14+
> : ^^^^^
15+
>1 : 1
16+
> : ^
17+
18+
A,
19+
>A : E.A
20+
> : ^^^
21+
22+
foo = 10,
23+
>foo : E.foo
24+
> : ^^^^^
25+
>10 : 10
26+
> : ^^
27+
}
28+
E.A.toString();
29+
>E.A.toString() : string
30+
> : ^^^^^^
31+
>E.A.toString : (radix?: number) => string
32+
> : ^ ^^^ ^^^^^
33+
>E.A : E.A
34+
> : ^^^
35+
>E : typeof E
36+
> : ^^^^^^^^
37+
>A : E.A
38+
> : ^^^
39+
>toString : (radix?: number) => string
40+
> : ^ ^^^ ^^^^^
41+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
// https://github.com/microsoft/TypeScript/issues/63173
5+
6+
declare const enum E {
7+
[foo] = 1,
8+
A,
9+
foo = 10,
10+
}
11+
E.A.toString();

0 commit comments

Comments
 (0)