File tree Expand file tree Collapse file tree 5 files changed +72
-1
lines changed
src/compiler/transformers Expand file tree Collapse file tree 5 files changed +72
-1
lines changed Original file line number Diff line number Diff line change @@ -2861,7 +2861,6 @@ namespace ts {
28612861 const moduleBlock = < ModuleBlock > getInnerMostModuleDeclarationFromDottedModule ( node ) . body ;
28622862 statementsLocation = moveRangePos ( moduleBlock . statements , - 1 ) ;
28632863 }
2864-
28652864 addRange ( statements , endLexicalEnvironment ( ) ) ;
28662865
28672866 currentNamespaceContainerName = savedCurrentNamespaceContainerName ;
@@ -2874,6 +2873,30 @@ namespace ts {
28742873 /*location*/ blockLocation ,
28752874 /*multiLine*/ true
28762875 ) ;
2876+
2877+ // namespace hello.hi.world {
2878+ // function foo() {}
2879+ //
2880+ // // TODO, blah
2881+ // }
2882+ //
2883+ // should be emitted as
2884+ //
2885+ // var hello;
2886+ // (function (hello) {
2887+ // var hi;
2888+ // (function (hi) {
2889+ // var world;
2890+ // (function (world) {
2891+ // function foo() { }
2892+ // // TODO, blah
2893+ // })(world = hi.world || (hi.world = {}));
2894+ // })(hi = hello.hi || (hello.hi = {}));
2895+ // })(hello || (hello = {}));
2896+ // We only want to emit comment on the namespace which contains block body itself, not the containing namespaces.
2897+ if ( body . kind !== SyntaxKind . ModuleBlock ) {
2898+ setNodeEmitFlags ( block , block . emitFlags | NodeEmitFlags . NoComments ) ;
2899+ }
28772900 return block ;
28782901 }
28792902
Original file line number Diff line number Diff line change 1+ //// [commentInNamespaceDeclarationWithIdentifierPathName.ts]
2+ namespace hello . hi . world
3+ {
4+ function foo ( ) { }
5+
6+ // TODO, blah
7+ }
8+
9+ //// [commentInNamespaceDeclarationWithIdentifierPathName.js]
10+ var hello ;
11+ ( function ( hello ) {
12+ var hi ;
13+ ( function ( hi ) {
14+ var world ;
15+ ( function ( world ) {
16+ function foo ( ) { }
17+ // TODO, blah
18+ } ) ( world = hi . world || ( hi . world = { } ) ) ;
19+ } ) ( hi = hello . hi || ( hello . hi = { } ) ) ;
20+ } ) ( hello || ( hello = { } ) ) ;
Original file line number Diff line number Diff line change 1+ === tests/cases/compiler/commentInNamespaceDeclarationWithIdentifierPathName.ts ===
2+ namespace hello.hi.world
3+ >hello : Symbol(hello, Decl(commentInNamespaceDeclarationWithIdentifierPathName.ts, 0, 0))
4+ >hi : Symbol(hi, Decl(commentInNamespaceDeclarationWithIdentifierPathName.ts, 0, 16))
5+ >world : Symbol(world, Decl(commentInNamespaceDeclarationWithIdentifierPathName.ts, 0, 19))
6+ {
7+ function foo() {}
8+ >foo : Symbol(foo, Decl(commentInNamespaceDeclarationWithIdentifierPathName.ts, 1, 1))
9+
10+ // TODO, blah
11+ }
Original file line number Diff line number Diff line change 1+ === tests/cases/compiler/commentInNamespaceDeclarationWithIdentifierPathName.ts ===
2+ namespace hello.hi.world
3+ >hello : typeof hello
4+ >hi : typeof hi
5+ >world : typeof world
6+ {
7+ function foo() {}
8+ >foo : () => void
9+
10+ // TODO, blah
11+ }
Original file line number Diff line number Diff line change 1+ namespace hello . hi . world
2+ {
3+ function foo ( ) { }
4+
5+ // TODO, blah
6+ }
You can’t perform that action at this time.
0 commit comments