Skip to content

Commit 6db4faf

Browse files
committed
Merge pull request microsoft#3545 from Microsoft/emitNamespaces
Emit declarations of namespaces correctly
2 parents 7361d68 + 53579f0 commit 6db4faf

File tree

6 files changed

+70
-2
lines changed

6 files changed

+70
-2
lines changed

Jakefile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].conca
369369
// Create the node definition file by replacing 'ts' module with '"typescript"' as a module.
370370
jake.cpR(standaloneDefinitionsFile, nodeDefinitionsFile, {silent: true});
371371
var definitionFileContents = fs.readFileSync(nodeDefinitionsFile).toString();
372-
definitionFileContents = definitionFileContents.replace(/declare module ts/g, 'declare module "typescript"');
372+
definitionFileContents = definitionFileContents.replace(/declare (namespace|module) ts/g, 'declare module "typescript"');
373373
fs.writeFileSync(nodeDefinitionsFile, definitionFileContents);
374374
});
375375

src/compiler/declarationEmitter.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,12 @@ namespace ts {
709709
function writeModuleDeclaration(node: ModuleDeclaration) {
710710
emitJsDocComments(node);
711711
emitModuleElementDeclarationFlags(node);
712-
write("module ");
712+
if (node.flags & NodeFlags.Namespace) {
713+
write("namespace ");
714+
}
715+
else {
716+
write("module ");
717+
}
713718
writeTextOfNode(currentSourceFile, node.name);
714719
while (node.body.kind !== SyntaxKind.ModuleBlock) {
715720
node = <ModuleDeclaration>node.body;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//// [namespacesDeclaration.ts]
2+
3+
module M {
4+
export namespace N {
5+
export module M2 {
6+
export interface I {}
7+
}
8+
}
9+
}
10+
11+
//// [namespacesDeclaration.js]
12+
13+
14+
//// [namespacesDeclaration.d.ts]
15+
declare module M {
16+
namespace N {
17+
module M2 {
18+
interface I {
19+
}
20+
}
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/namespacesDeclaration.ts ===
2+
3+
module M {
4+
>M : Symbol(M, Decl(namespacesDeclaration.ts, 0, 0))
5+
6+
export namespace N {
7+
>N : Symbol(N, Decl(namespacesDeclaration.ts, 1, 10))
8+
9+
export module M2 {
10+
>M2 : Symbol(M2, Decl(namespacesDeclaration.ts, 2, 23))
11+
12+
export interface I {}
13+
>I : Symbol(I, Decl(namespacesDeclaration.ts, 3, 24))
14+
}
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/namespacesDeclaration.ts ===
2+
3+
module M {
4+
>M : any
5+
6+
export namespace N {
7+
>N : any
8+
9+
export module M2 {
10+
>M2 : any
11+
12+
export interface I {}
13+
>I : I
14+
}
15+
}
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @declaration: true
2+
3+
module M {
4+
export namespace N {
5+
export module M2 {
6+
export interface I {}
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)