diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index e4fb8a0aaf0..1cb63f55e91 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -279,7 +279,7 @@ namespace ts { else if (node.transformFlags & TransformFlags.ContainsES2015 || (isInConstructorWithCapturedSuper && !isExpression(node))) { // we want to dive in this branch either if node has children with ES2015 specific syntax // or we are inside constructor that captures result of the super call so all returns without expression should be - // rewritten. Note: we skip expressions since returns should never appear there + // rewritten. Note: we skip expressions since returns should never appear there return visitEachChild(node, visitor, context); } else { @@ -1011,7 +1011,20 @@ namespace ts { // Return the result if we have an immediate super() call on the last statement. if (superCallExpression && statementOffset === ctorStatements.length - 1) { - statements.push(createReturn(superCallExpression)); + const returnStatement = createReturn(superCallExpression); + + if (superCallExpression.kind !== SyntaxKind.BinaryExpression + && (superCallExpression as BinaryExpression).left.kind !== SyntaxKind.CallExpression) { + Debug.fail("Assumed generated super call would have form 'super.call(...) || this'."); + } + + // Shift comments from the original super call to the return statement. + setCommentRange(returnStatement, getCommentRange( + setEmitFlags( + (superCallExpression as BinaryExpression).left, + EmitFlags.NoComments))); + + statements.push(returnStatement); return SuperCaptureResult.ReplaceWithReturn; }