From 3d224bde486718efb965f05dafcaa674de53e59b Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 17 Jun 2015 17:50:03 -0700 Subject: [PATCH 1/3] Emit declarations of namespaces correctelly --- Jakefile.js | 2 +- src/compiler/declarationEmitter.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 1f88ee39082..cf7f9b3af22 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -361,7 +361,7 @@ compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].conca // Create the node definition file by replacing 'ts' module with '"typescript"' as a module. jake.cpR(standaloneDefinitionsFile, nodeDefinitionsFile, {silent: true}); var definitionFileContents = fs.readFileSync(nodeDefinitionsFile).toString(); - definitionFileContents = definitionFileContents.replace(/declare module ts/g, 'declare module "typescript"'); + definitionFileContents = definitionFileContents.replace(/declare namespace ts/g, 'declare module "typescript"'); fs.writeFileSync(nodeDefinitionsFile, definitionFileContents); }); diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index a2edc632de3..2ba88f1ac29 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -709,7 +709,12 @@ namespace ts { function writeModuleDeclaration(node: ModuleDeclaration) { emitJsDocComments(node); emitModuleElementDeclarationFlags(node); - write("module "); + if (node.flags & NodeFlags.Namespace) { + write("namespace "); + } + else { + write("module "); + } writeTextOfNode(currentSourceFile, node.name); while (node.body.kind !== SyntaxKind.ModuleBlock) { node = node.body; From 54ed3c475e4e1b21c8058028af23784d4dc1d05a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 17 Jun 2015 21:20:20 -0700 Subject: [PATCH 2/3] Add a unit test --- .../reference/namespacesDeclaration.js | 22 +++++++++++++++++++ .../reference/namespacesDeclaration.symbols | 16 ++++++++++++++ .../reference/namespacesDeclaration.types | 16 ++++++++++++++ tests/cases/compiler/namespacesDeclaration.ts | 9 ++++++++ 4 files changed, 63 insertions(+) create mode 100644 tests/baselines/reference/namespacesDeclaration.js create mode 100644 tests/baselines/reference/namespacesDeclaration.symbols create mode 100644 tests/baselines/reference/namespacesDeclaration.types create mode 100644 tests/cases/compiler/namespacesDeclaration.ts diff --git a/tests/baselines/reference/namespacesDeclaration.js b/tests/baselines/reference/namespacesDeclaration.js new file mode 100644 index 00000000000..7c7cfa84af0 --- /dev/null +++ b/tests/baselines/reference/namespacesDeclaration.js @@ -0,0 +1,22 @@ +//// [namespacesDeclaration.ts] + +module M { + export namespace N { + export module M2 { + export interface I {} + } + } +} + +//// [namespacesDeclaration.js] + + +//// [namespacesDeclaration.d.ts] +declare module M { + namespace N { + module M2 { + interface I { + } + } + } +} diff --git a/tests/baselines/reference/namespacesDeclaration.symbols b/tests/baselines/reference/namespacesDeclaration.symbols new file mode 100644 index 00000000000..1706f212f34 --- /dev/null +++ b/tests/baselines/reference/namespacesDeclaration.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/namespacesDeclaration.ts === + +module M { +>M : Symbol(M, Decl(namespacesDeclaration.ts, 0, 0)) + + export namespace N { +>N : Symbol(N, Decl(namespacesDeclaration.ts, 1, 10)) + + export module M2 { +>M2 : Symbol(M2, Decl(namespacesDeclaration.ts, 2, 23)) + + export interface I {} +>I : Symbol(I, Decl(namespacesDeclaration.ts, 3, 24)) + } + } +} diff --git a/tests/baselines/reference/namespacesDeclaration.types b/tests/baselines/reference/namespacesDeclaration.types new file mode 100644 index 00000000000..944098097fc --- /dev/null +++ b/tests/baselines/reference/namespacesDeclaration.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/namespacesDeclaration.ts === + +module M { +>M : any + + export namespace N { +>N : any + + export module M2 { +>M2 : any + + export interface I {} +>I : I + } + } +} diff --git a/tests/cases/compiler/namespacesDeclaration.ts b/tests/cases/compiler/namespacesDeclaration.ts new file mode 100644 index 00000000000..a231cf2d9d1 --- /dev/null +++ b/tests/cases/compiler/namespacesDeclaration.ts @@ -0,0 +1,9 @@ +// @declaration: true + +module M { + export namespace N { + export module M2 { + export interface I {} + } + } +} \ No newline at end of file From 53579f089e920c811b6b7de848f0f52dbf702790 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 17 Jun 2015 23:44:12 -0700 Subject: [PATCH 3/3] support modules as well as namespaces in external module conversion --- Jakefile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jakefile.js b/Jakefile.js index cf7f9b3af22..07d48bbc133 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -361,7 +361,7 @@ compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].conca // Create the node definition file by replacing 'ts' module with '"typescript"' as a module. jake.cpR(standaloneDefinitionsFile, nodeDefinitionsFile, {silent: true}); var definitionFileContents = fs.readFileSync(nodeDefinitionsFile).toString(); - definitionFileContents = definitionFileContents.replace(/declare namespace ts/g, 'declare module "typescript"'); + definitionFileContents = definitionFileContents.replace(/declare (namespace|module) ts/g, 'declare module "typescript"'); fs.writeFileSync(nodeDefinitionsFile, definitionFileContents); });