From 6036c927849d0b66ccde6b4e1b3d2f138c15d3b3 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 15 Aug 2014 15:24:44 -0700 Subject: [PATCH] Emit leading/trailing comments of ifStatement --- src/compiler/emitter.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 2610aed6c22..025935f5de3 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -924,6 +924,11 @@ module ts { } function emitIfStatement(node: IfStatement) { + // emit comments only if this is not else if statement as else if will take care of emitting the leading/trailing comments + if (node.parent.kind !== SyntaxKind.IfStatement || (node.parent).elseStatement !== node) { + emitLeadingComments(node); + } + emitLeadingComments(node); var endPos = emitToken(SyntaxKind.IfKeyword, node.pos); write(" "); endPos = emitToken(SyntaxKind.OpenParenToken, endPos); @@ -932,6 +937,7 @@ module ts { emitEmbeddedStatement(node.thenStatement); if (node.elseStatement) { writeLine(); + emitLeadingComments(node.elseStatement); emitToken(SyntaxKind.ElseKeyword, node.thenStatement.end); if (node.elseStatement.kind === SyntaxKind.IfStatement) { write(" "); @@ -941,6 +947,7 @@ module ts { emitEmbeddedStatement(node.elseStatement); } } + emitTrailingComments(node); } function emitDoStatement(node: DoStatement) {