Skip to content

Fix 10741: Only emit comment only once in module declaration with identifier pat… #10766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2859,7 +2859,6 @@ namespace ts {
const moduleBlock = <ModuleBlock>getInnerMostModuleDeclarationFromDottedModule(node).body;
statementsLocation = moveRangePos(moduleBlock.statements, -1);
}

addRange(statements, endLexicalEnvironment());

currentNamespaceContainerName = savedCurrentNamespaceContainerName;
Expand All @@ -2872,6 +2871,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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 = {}));
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace hello.hi.world
{
function foo() {}

// TODO, blah
}