Don't replace the last statement if 'this' is used/captured within the constructor.

This commit is contained in:
Daniel Rosenwasser
2016-12-13 11:58:58 -08:00
parent e5e1533d49
commit 7da4b857f2
+5 -2
View File
@@ -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