mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-11 16:38:46 -05:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = {}));
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace hello.hi.world
|
||||
{
|
||||
function foo() {}
|
||||
|
||||
// TODO, blah
|
||||
}
|
||||
Reference in New Issue
Block a user