Move comments from super calls to their generated return statements.

This commit is contained in:
Daniel Rosenwasser 2016-11-12 02:56:25 -08:00
parent 63f70dc09a
commit 2f6ba0876c

View File

@ -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;
}