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
14 changes: 9 additions & 5 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5526,13 +5526,17 @@ const _super = (function (geti, seti) {
// If the class has static properties, and it's a class expression, then we'll need
// to specialize the emit a bit. for a class expression of the form:
//
// class C { static a = 1; static b = 2; ... }
// (class C { static a = 1; static b = 2; ... })
//
// We'll emit:
//
// let C_1 = class C{};
// C_1.a = 1;
// C_1.b = 2; // so forth and so on
// ((C_1 = class C {
// // Normal class body
// },
// C_1.a = 1,
// C_1.b = 2,
// C_1));
// var C_1;
//
// This keeps the expression as an expression, while ensuring that the static parts
// of it have been initialized by the time it is used.
Expand All @@ -5541,7 +5545,7 @@ const _super = (function (geti, seti) {
let generatedName: string;

if (isClassExpressionWithStaticProperties) {
generatedName = getGeneratedNameForNode(node.name);
generatedName = node.name ? getGeneratedNameForNode(node.name) : makeUniqueName("classExpression");
const synthesizedNode = <Identifier>createSynthesizedNode(SyntaxKind.Identifier);
synthesizedNode.text = generatedName;
recordTempDeclaration(synthesizedNode);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [classExpressionWithStaticPropertiesES64.ts]
(class { static x = 0; });


//// [classExpressionWithStaticPropertiesES64.js]
((classExpression_1 = class {
},
classExpression_1.x = 0,
classExpression_1));
var classExpression_1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== tests/cases/compiler/classExpressionWithStaticPropertiesES64.ts ===
(class { static x = 0; });
>x : Symbol((Anonymous class).x, Decl(classExpressionWithStaticPropertiesES64.ts, 0, 8))

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/compiler/classExpressionWithStaticPropertiesES64.ts ===
(class { static x = 0; });
>(class { static x = 0; }) : typeof (Anonymous class)
>class { static x = 0; } : typeof (Anonymous class)
>x : number
>0 : number

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @target: es6
(class { static x = 0; });