diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9c36dff481f5c..ced8becb97126 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -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. @@ -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 = createSynthesizedNode(SyntaxKind.Identifier); synthesizedNode.text = generatedName; recordTempDeclaration(synthesizedNode); diff --git a/tests/baselines/reference/classExpressionWithStaticPropertiesES64.js b/tests/baselines/reference/classExpressionWithStaticPropertiesES64.js new file mode 100644 index 0000000000000..ac09415bc0e4e --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticPropertiesES64.js @@ -0,0 +1,10 @@ +//// [classExpressionWithStaticPropertiesES64.ts] +(class { static x = 0; }); + + +//// [classExpressionWithStaticPropertiesES64.js] +((classExpression_1 = class { + }, + classExpression_1.x = 0, + classExpression_1)); +var classExpression_1; diff --git a/tests/baselines/reference/classExpressionWithStaticPropertiesES64.symbols b/tests/baselines/reference/classExpressionWithStaticPropertiesES64.symbols new file mode 100644 index 0000000000000..1289a526e4a64 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticPropertiesES64.symbols @@ -0,0 +1,4 @@ +=== tests/cases/compiler/classExpressionWithStaticPropertiesES64.ts === +(class { static x = 0; }); +>x : Symbol((Anonymous class).x, Decl(classExpressionWithStaticPropertiesES64.ts, 0, 8)) + diff --git a/tests/baselines/reference/classExpressionWithStaticPropertiesES64.types b/tests/baselines/reference/classExpressionWithStaticPropertiesES64.types new file mode 100644 index 0000000000000..f48ec6fdde6b6 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithStaticPropertiesES64.types @@ -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 + diff --git a/tests/cases/compiler/classExpressionWithStaticPropertiesES64.ts b/tests/cases/compiler/classExpressionWithStaticPropertiesES64.ts new file mode 100644 index 0000000000000..0d1c118d21431 --- /dev/null +++ b/tests/cases/compiler/classExpressionWithStaticPropertiesES64.ts @@ -0,0 +1,2 @@ +// @target: es6 +(class { static x = 0; });