Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13549,7 +13549,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
for (const declaration of symbol.declarations) {
if (declaration.kind === SyntaxKind.EnumDeclaration) {
for (const member of (declaration as EnumDeclaration).members) {
if (hasBindableName(member)) {
if (!hasDynamicName(member)) {
const memberSymbol = getSymbolOfDeclaration(member);
const value = getEnumMemberValue(member).value;
const memberType = getFreshTypeOfLiteralType(
Expand Down
15 changes: 15 additions & 0 deletions tests/baselines/reference/computedEnumMemberKeyNoCrash1.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
computedEnumMemberKeyNoCrash1.ts(4,5): error TS1164: Computed property names are not allowed in enums.


==== computedEnumMemberKeyNoCrash1.ts (1 errors) ====
// https://github.com/microsoft/TypeScript/issues/63173

declare const enum E {
[foo] = 1,
~~~~~
!!! error TS1164: Computed property names are not allowed in enums.
A,
foo = 10,
}
E.A.toString();

25 changes: 25 additions & 0 deletions tests/baselines/reference/computedEnumMemberKeyNoCrash1.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [tests/cases/compiler/computedEnumMemberKeyNoCrash1.ts] ////

=== computedEnumMemberKeyNoCrash1.ts ===
// https://github.com/microsoft/TypeScript/issues/63173

declare const enum E {
>E : Symbol(E, Decl(computedEnumMemberKeyNoCrash1.ts, 0, 0))

[foo] = 1,
>[foo] : Symbol(E[foo], Decl(computedEnumMemberKeyNoCrash1.ts, 2, 22))
>foo : Symbol(E.foo, Decl(computedEnumMemberKeyNoCrash1.ts, 4, 6))

A,
>A : Symbol(E.A, Decl(computedEnumMemberKeyNoCrash1.ts, 3, 14))

foo = 10,
>foo : Symbol(E.foo, Decl(computedEnumMemberKeyNoCrash1.ts, 4, 6))
}
E.A.toString();
>E.A.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))
>E.A : Symbol(E.A, Decl(computedEnumMemberKeyNoCrash1.ts, 3, 14))
>E : Symbol(E, Decl(computedEnumMemberKeyNoCrash1.ts, 0, 0))
>A : Symbol(E.A, Decl(computedEnumMemberKeyNoCrash1.ts, 3, 14))
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))

41 changes: 41 additions & 0 deletions tests/baselines/reference/computedEnumMemberKeyNoCrash1.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//// [tests/cases/compiler/computedEnumMemberKeyNoCrash1.ts] ////

=== computedEnumMemberKeyNoCrash1.ts ===
// https://github.com/microsoft/TypeScript/issues/63173

declare const enum E {
>E : E
> : ^

[foo] = 1,
>[foo] : E
> : ^
>foo : E.foo
> : ^^^^^
>1 : 1
> : ^

A,
>A : E.A
> : ^^^

foo = 10,
>foo : E.foo
> : ^^^^^
>10 : 10
> : ^^
}
E.A.toString();
>E.A.toString() : string
> : ^^^^^^
>E.A.toString : (radix?: number) => string
> : ^ ^^^ ^^^^^
>E.A : E.A
> : ^^^
>E : typeof E
> : ^^^^^^^^
>A : E.A
> : ^^^
>toString : (radix?: number) => string
> : ^ ^^^ ^^^^^

11 changes: 11 additions & 0 deletions tests/cases/compiler/computedEnumMemberKeyNoCrash1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @strict: true
// @noEmit: true

// https://github.com/microsoft/TypeScript/issues/63173

declare const enum E {
[foo] = 1,
A,
foo = 10,
}
E.A.toString();