Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for computed properties in instance initializers #31517

Merged
merged 1 commit into from May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/compiler/emitter.ts
Expand Up @@ -4527,6 +4527,8 @@ namespace ts {
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
return generateNameForMethodOrAccessor(<MethodDeclaration | AccessorDeclaration>node);
case SyntaxKind.ComputedPropertyName:
return makeTempVariableName(TempFlags.Auto, /*reserveInNestedScopes*/ true);
default:
return makeTempVariableName(TempFlags.Auto);
}
Expand Down
@@ -0,0 +1,22 @@
//// [instanceMemberWithComputedPropertyName.ts]
// https://github.com/microsoft/TypeScript/issues/30953
const x = 1;
class C {
[x] = true;
constructor() {
const { a, b } = { a: 1, b: 2 };
}
}

//// [instanceMemberWithComputedPropertyName.js]
var _a;
// https://github.com/microsoft/TypeScript/issues/30953
var x = 1;
var C = /** @class */ (function () {
function C() {
this[_a] = true;
var _b = { a: 1, b: 2 }, a = _b.a, b = _b.b;
}
return C;
}());
_a = x;
@@ -0,0 +1,20 @@
=== tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberWithComputedPropertyName.ts ===
// https://github.com/microsoft/TypeScript/issues/30953
const x = 1;
>x : Symbol(x, Decl(instanceMemberWithComputedPropertyName.ts, 1, 5))

class C {
>C : Symbol(C, Decl(instanceMemberWithComputedPropertyName.ts, 1, 12))

[x] = true;
>[x] : Symbol(C[x], Decl(instanceMemberWithComputedPropertyName.ts, 2, 9))
>x : Symbol(x, Decl(instanceMemberWithComputedPropertyName.ts, 1, 5))

constructor() {
const { a, b } = { a: 1, b: 2 };
>a : Symbol(a, Decl(instanceMemberWithComputedPropertyName.ts, 5, 15))
>b : Symbol(b, Decl(instanceMemberWithComputedPropertyName.ts, 5, 18))
>a : Symbol(a, Decl(instanceMemberWithComputedPropertyName.ts, 5, 26))
>b : Symbol(b, Decl(instanceMemberWithComputedPropertyName.ts, 5, 32))
}
}
@@ -0,0 +1,25 @@
=== tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberWithComputedPropertyName.ts ===
// https://github.com/microsoft/TypeScript/issues/30953
const x = 1;
>x : 1
>1 : 1

class C {
>C : C

[x] = true;
>[x] : boolean
>x : 1
>true : true

constructor() {
const { a, b } = { a: 1, b: 2 };
>a : number
>b : number
>{ a: 1, b: 2 } : { a: number; b: number; }
>a : number
>1 : 1
>b : number
>2 : 2
}
}
@@ -0,0 +1,8 @@
// https://github.com/microsoft/TypeScript/issues/30953
const x = 1;
class C {
[x] = true;
constructor() {
const { a, b } = { a: 1, b: 2 };
}
}