From 7b07d3ce27e75c165b60b4dc06a84352941f793c Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 13 Apr 2016 11:59:29 -0700 Subject: [PATCH] Fix the trailing comment emit for module declaration Fixes #8045 Fixes: - tests\cases\compiler\augmentedTypesClass3.ts - tests\cases\compiler\augmentedTypesModules.ts - tests\cases\compiler\commentsModules.ts --- src/compiler/comments.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/compiler/comments.ts b/src/compiler/comments.ts index 1baf1847f04..4ecf2dd6935 100644 --- a/src/compiler/comments.ts +++ b/src/compiler/comments.ts @@ -117,6 +117,25 @@ namespace ts { return undefined; } + const node = range as Node; + if (node.kind === SyntaxKind.VariableStatement && + node.original && + node.original.kind === SyntaxKind.ModuleDeclaration) { + // Trailing comments for module declaration should be emitted with function closure instead of variable statement + // /** Module comment*/ + // module m1 { + // function foo4Export() { + // } + // } // trailing comment module + // Should emit + // /** Module comment*/ + // var m1; + // (function (m1) { + // function foo4Export() { + // } + // })(m1 || (m1 = {})); // trailing comment module + return undefined; + } return getTrailingCommentsOfPosition(range.end); }