Merge pull request #10766 from Microsoft/fix10741_emitCommentOnlyOnce

Fix 10741: Only emit comment only once in module declaration with identifier pat…
This commit is contained in:
Yui
2016-09-16 16:30:40 -07:00
committed by GitHub
5 changed files with 72 additions and 1 deletions

View File

@@ -2861,7 +2861,6 @@ namespace ts {
const moduleBlock = <ModuleBlock>getInnerMostModuleDeclarationFromDottedModule(node).body;
statementsLocation = moveRangePos(moduleBlock.statements, -1);
}
addRange(statements, endLexicalEnvironment());
currentNamespaceContainerName = savedCurrentNamespaceContainerName;
@@ -2874,6 +2873,30 @@ namespace ts {
/*location*/ blockLocation,
/*multiLine*/ true
);
// namespace hello.hi.world {
// function foo() {}
//
// // TODO, blah
// }
//
// should be emitted as
//
// var hello;
// (function (hello) {
// var hi;
// (function (hi) {
// var world;
// (function (world) {
// function foo() { }
// // TODO, blah
// })(world = hi.world || (hi.world = {}));
// })(hi = hello.hi || (hello.hi = {}));
// })(hello || (hello = {}));
// We only want to emit comment on the namespace which contains block body itself, not the containing namespaces.
if (body.kind !== SyntaxKind.ModuleBlock) {
setNodeEmitFlags(block, block.emitFlags | NodeEmitFlags.NoComments);
}
return block;
}

View File

@@ -0,0 +1,20 @@
//// [commentInNamespaceDeclarationWithIdentifierPathName.ts]
namespace hello.hi.world
{
function foo() {}
// TODO, blah
}
//// [commentInNamespaceDeclarationWithIdentifierPathName.js]
var hello;
(function (hello) {
var hi;
(function (hi) {
var world;
(function (world) {
function foo() { }
// TODO, blah
})(world = hi.world || (hi.world = {}));
})(hi = hello.hi || (hello.hi = {}));
})(hello || (hello = {}));

View File

@@ -0,0 +1,11 @@
=== tests/cases/compiler/commentInNamespaceDeclarationWithIdentifierPathName.ts ===
namespace hello.hi.world
>hello : Symbol(hello, Decl(commentInNamespaceDeclarationWithIdentifierPathName.ts, 0, 0))
>hi : Symbol(hi, Decl(commentInNamespaceDeclarationWithIdentifierPathName.ts, 0, 16))
>world : Symbol(world, Decl(commentInNamespaceDeclarationWithIdentifierPathName.ts, 0, 19))
{
function foo() {}
>foo : Symbol(foo, Decl(commentInNamespaceDeclarationWithIdentifierPathName.ts, 1, 1))
// TODO, blah
}

View File

@@ -0,0 +1,11 @@
=== tests/cases/compiler/commentInNamespaceDeclarationWithIdentifierPathName.ts ===
namespace hello.hi.world
>hello : typeof hello
>hi : typeof hi
>world : typeof world
{
function foo() {}
>foo : () => void
// TODO, blah
}

View File

@@ -0,0 +1,6 @@
namespace hello.hi.world
{
function foo() {}
// TODO, blah
}