Skip to content

Commit

Permalink
fix(49594): allow enum members in computed properties
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tarasyuk committed Jun 21, 2022
1 parent 74d76e9 commit 4a77306
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Expand Up @@ -23337,7 +23337,7 @@ namespace ts {
}
if (isEntityNameExpression(node.argumentExpression)) {
const symbol = resolveEntityName(node.argumentExpression, SymbolFlags.Value, /*ignoreErrors*/ true);
if (!symbol || !isConstVariable(symbol)) return undefined;
if (!symbol || !(isConstVariable(symbol) || (symbol.flags & SymbolFlags.EnumMember))) return undefined;

const declaration = symbol.valueDeclaration;
if (declaration === undefined) return undefined;
Expand Down
12 changes: 12 additions & 0 deletions tests/baselines/reference/strictPropertyInitialization.errors.txt
Expand Up @@ -179,4 +179,16 @@ tests/cases/conformance/classes/propertyMemberDeclarations/strictPropertyInitial
this['c'] = 1;
}
}

enum E {
A = "A",
B = "B"
}
class C13 {
[E.A]: number;

constructor() {
this[E.A] = 1;
}
}

31 changes: 31 additions & 0 deletions tests/baselines/reference/strictPropertyInitialization.js
Expand Up @@ -147,6 +147,18 @@ class C12 {
this['c'] = 1;
}
}

enum E {
A = "A",
B = "B"
}
class C13 {
[E.A]: number;

constructor() {
this[E.A] = 1;
}
}


//// [strictPropertyInitialization.js]
Expand Down Expand Up @@ -259,6 +271,17 @@ class C12 {
this['c'] = 1;
}
}
var E;
(function (E) {
E["A"] = "A";
E["B"] = "B";
})(E || (E = {}));
class C13 {
constructor() {
this[E.A] = 1;
}
}
E.A;


//// [strictPropertyInitialization.d.ts]
Expand Down Expand Up @@ -335,3 +358,11 @@ declare class C12 {
['c']: number;
constructor();
}
declare enum E {
A = "A",
B = "B"
}
declare class C13 {
[E.A]: number;
constructor();
}
27 changes: 27 additions & 0 deletions tests/baselines/reference/strictPropertyInitialization.symbols
Expand Up @@ -348,3 +348,30 @@ class C12 {
}
}

enum E {
>E : Symbol(E, Decl(strictPropertyInitialization.ts, 147, 1))

A = "A",
>A : Symbol(E.A, Decl(strictPropertyInitialization.ts, 149, 8))

B = "B"
>B : Symbol(E.B, Decl(strictPropertyInitialization.ts, 150, 12))
}
class C13 {
>C13 : Symbol(C13, Decl(strictPropertyInitialization.ts, 152, 1))

[E.A]: number;
>[E.A] : Symbol(C13[E.A], Decl(strictPropertyInitialization.ts, 153, 11))
>E.A : Symbol(E.A, Decl(strictPropertyInitialization.ts, 149, 8))
>E : Symbol(E, Decl(strictPropertyInitialization.ts, 147, 1))
>A : Symbol(E.A, Decl(strictPropertyInitialization.ts, 149, 8))

constructor() {
this[E.A] = 1;
>this : Symbol(C13, Decl(strictPropertyInitialization.ts, 152, 1))
>E.A : Symbol(E.A, Decl(strictPropertyInitialization.ts, 149, 8))
>E : Symbol(E, Decl(strictPropertyInitialization.ts, 147, 1))
>A : Symbol(E.A, Decl(strictPropertyInitialization.ts, 149, 8))
}
}

32 changes: 32 additions & 0 deletions tests/baselines/reference/strictPropertyInitialization.types
Expand Up @@ -395,3 +395,35 @@ class C12 {
}
}

enum E {
>E : E

A = "A",
>A : E.A
>"A" : "A"

B = "B"
>B : E.B
>"B" : "B"
}
class C13 {
>C13 : C13

[E.A]: number;
>[E.A] : number
>E.A : E.A
>E : typeof E
>A : E.A

constructor() {
this[E.A] = 1;
>this[E.A] = 1 : 1
>this[E.A] : number
>this : this
>E.A : E.A
>E : typeof E
>A : E.A
>1 : 1
}
}

Expand Up @@ -150,3 +150,15 @@ class C12 {
this['c'] = 1;
}
}

enum E {
A = "A",
B = "B"
}
class C13 {
[E.A]: number;

constructor() {
this[E.A] = 1;
}
}

0 comments on commit 4a77306

Please sign in to comment.