Skip to content

Commit 2f6ba08

Browse files
Move comments from super calls to their generated return statements.
1 parent 63f70dc commit 2f6ba08

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/compiler/transformers/es2015.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ namespace ts {
279279
else if (node.transformFlags & TransformFlags.ContainsES2015 || (isInConstructorWithCapturedSuper && !isExpression(node))) {
280280
// we want to dive in this branch either if node has children with ES2015 specific syntax
281281
// or we are inside constructor that captures result of the super call so all returns without expression should be
282-
// rewritten. Note: we skip expressions since returns should never appear there
282+
// rewritten. Note: we skip expressions since returns should never appear there
283283
return visitEachChild(node, visitor, context);
284284
}
285285
else {
@@ -1011,7 +1011,20 @@ namespace ts {
10111011

10121012
// Return the result if we have an immediate super() call on the last statement.
10131013
if (superCallExpression && statementOffset === ctorStatements.length - 1) {
1014-
statements.push(createReturn(superCallExpression));
1014+
const returnStatement = createReturn(superCallExpression);
1015+
1016+
if (superCallExpression.kind !== SyntaxKind.BinaryExpression
1017+
&& (superCallExpression as BinaryExpression).left.kind !== SyntaxKind.CallExpression) {
1018+
Debug.fail("Assumed generated super call would have form 'super.call(...) || this'.");
1019+
}
1020+
1021+
// Shift comments from the original super call to the return statement.
1022+
setCommentRange(returnStatement, getCommentRange(
1023+
setEmitFlags(
1024+
(superCallExpression as BinaryExpression).left,
1025+
EmitFlags.NoComments)));
1026+
1027+
statements.push(returnStatement);
10151028
return SuperCaptureResult.ReplaceWithReturn;
10161029
}
10171030

0 commit comments

Comments
 (0)