Skip to content

Commit 423d8a0

Browse files
committed
PR feedback
1 parent b69afd1 commit 423d8a0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/compiler/transformers/es2015.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3360,10 +3360,13 @@ namespace ts {
33603360
const classStatements = visitNodes(body.statements, visitor, isStatement, 0, 1);
33613361
const remainingStatements = visitNodes(body.statements, visitor, isStatement, 1, body.statements.length - 1);
33623362
const varStatement = cast(firstOrUndefined(classStatements), isVariableStatement);
3363+
3364+
// We know there is only one variable declaration here as we verified this in an
3365+
// earlier call to isTypeScriptClassWrapper
33633366
const variable = varStatement.declarationList.declarations[0];
33643367
const initializer = skipOuterExpressions(variable.initializer);
33653368

3366-
// Under certain conditions, the 'ts' transformer may may introduce a class alias, which
3369+
// Under certain conditions, the 'ts' transformer may introduce a class alias, which
33673370
// we see as an assignment, for example:
33683371
//
33693372
// (function () {

src/compiler/transformers/ts.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,17 @@ namespace ts {
573573
addConstructorDecorationStatement(statements, node);
574574

575575
if (facts & ClassFacts.UseImmediatelyInvokedFunctionExpression) {
576+
// When we emit a TypeScript class down to ES5, we must wrap it in an IIFE so that the
577+
// 'es2015' transformer can properly nest static initializers and decorators. The result
578+
// looks something like:
579+
//
580+
// var C = function () {
581+
// class C {
582+
// }
583+
// C.static_prop = 1;
584+
// return C;
585+
// }();
586+
//
576587
const closingBraceLocation = createTokenRange(skipTrivia(currentSourceFile.text, node.members.end), SyntaxKind.CloseBraceToken);
577588
const localName = getInternalName(node);
578589

0 commit comments

Comments
 (0)