From 7da4b857f2a0f05f0fe18694b64f0007783655cd Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 13 Dec 2016 11:58:58 -0800 Subject: [PATCH] Don't replace the last statement if 'this' is used/captured within the constructor. --- src/compiler/transformers/es2015.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index ad016972d0d..7f3f0bb8ba7 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -1024,8 +1024,11 @@ namespace ts { } } - // Return the result if we have an immediate super() call on the last statement. - if (superCallExpression && statementOffset === ctorStatements.length - 1) { + // Return the result if we have an immediate super() call on the last statement, + // but only if the constructor itself doesn't use 'this' elsewhere. + if (superCallExpression + && statementOffset === ctorStatements.length - 1 + && !(ctor.transformFlags & (TransformFlags.ContainsLexicalThis | TransformFlags.ContainsCapturedLexicalThis))) { const returnStatement = createReturn(superCallExpression); if (superCallExpression.kind !== SyntaxKind.BinaryExpression