Skip to content

Commit 7da4b85

Browse files
Don't replace the last statement if 'this' is used/captured within the constructor.
1 parent e5e1533 commit 7da4b85

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/compiler/transformers/es2015.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,8 +1024,11 @@ namespace ts {
10241024
}
10251025
}
10261026

1027-
// Return the result if we have an immediate super() call on the last statement.
1028-
if (superCallExpression && statementOffset === ctorStatements.length - 1) {
1027+
// Return the result if we have an immediate super() call on the last statement,
1028+
// but only if the constructor itself doesn't use 'this' elsewhere.
1029+
if (superCallExpression
1030+
&& statementOffset === ctorStatements.length - 1
1031+
&& !(ctor.transformFlags & (TransformFlags.ContainsLexicalThis | TransformFlags.ContainsCapturedLexicalThis))) {
10291032
const returnStatement = createReturn(superCallExpression);
10301033

10311034
if (superCallExpression.kind !== SyntaxKind.BinaryExpression

0 commit comments

Comments
 (0)