Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/transformers/classFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ namespace ts {
// Create a temporary variable to store a computed property name (if necessary).
// If it's not inlineable, then we emit an expression after the class which assigns
// the property name to the temporary variable.
const expr = getPropertyNameExpressionIfNeeded(node.name, !!node.initializer);
const expr = getPropertyNameExpressionIfNeeded(node.name, !!node.initializer || !!context.getCompilerOptions().useDefineForClassFields);
if (expr && !isSimpleInlineableExpression(expr)) {
(pendingExpressions || (pendingExpressions = [])).push(expr);
}
Expand All @@ -145,7 +145,7 @@ namespace ts {
}

const savedPendingExpressions = pendingExpressions;
pendingExpressions = undefined!;
pendingExpressions = undefined;

const extendsClauseElement = getEffectiveBaseTypeNode(node);
const isDerivedClass = !!(extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [instanceMemberWithComputedPropertyName2.ts]
// https://github.com/microsoft/TypeScript/issues/33857
"use strict";
const x = 1;
class C {
[x]: string;
}


//// [instanceMemberWithComputedPropertyName2.js]
// https://github.com/microsoft/TypeScript/issues/33857
"use strict";
var _a;
const x = 1;
class C {
constructor() {
Object.defineProperty(this, _a, {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
}
}
_a = x;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
=== tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberWithComputedPropertyName2.ts ===
// https://github.com/microsoft/TypeScript/issues/33857
"use strict";
const x = 1;
>x : Symbol(x, Decl(instanceMemberWithComputedPropertyName2.ts, 2, 5))

class C {
>C : Symbol(C, Decl(instanceMemberWithComputedPropertyName2.ts, 2, 12))

[x]: string;
>[x] : Symbol(C[x], Decl(instanceMemberWithComputedPropertyName2.ts, 3, 9))
>x : Symbol(x, Decl(instanceMemberWithComputedPropertyName2.ts, 2, 5))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberWithComputedPropertyName2.ts ===
// https://github.com/microsoft/TypeScript/issues/33857
"use strict";
>"use strict" : "use strict"

const x = 1;
>x : 1
>1 : 1

class C {
>C : C

[x]: string;
>[x] : string
>x : 1
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// https://github.com/microsoft/TypeScript/issues/33857
// @useDefineForClassFields: true
// @target: es2015
"use strict";
const x = 1;
class C {
[x]: string;
}