From f9a1fca38810823654315f0a90c969e76b6d7bfc Mon Sep 17 00:00:00 2001 From: Ika Date: Wed, 24 May 2017 02:07:34 +0800 Subject: [PATCH] Add missing emitter for NamespaceExportDeclaration (#16025) --- src/compiler/binder.ts | 1 + src/compiler/emitter.ts | 8 ++++++++ src/compiler/transformers/ts.ts | 3 +++ src/harness/unittests/printer.ts | 3 +++ .../printsNodeCorrectly.namespaceExportDeclaration.js | 1 + 5 files changed, 16 insertions(+) create mode 100644 tests/baselines/reference/printerApi/printsNodeCorrectly.namespaceExportDeclaration.js diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 30e2b7781f6..204a979d928 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -3398,6 +3398,7 @@ namespace ts { case SyntaxKind.IndexedAccessType: case SyntaxKind.MappedType: case SyntaxKind.LiteralType: + case SyntaxKind.NamespaceExportDeclaration: // Types and signatures are TypeScript syntax, and exclude all other facts. transformFlags = TransformFlags.AssertTypeScript; excludeFlags = TransformFlags.TypeExcludes; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 0cbb961e9f7..e00d46fe94e 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -571,6 +571,8 @@ namespace ts { return emitModuleBlock(node); case SyntaxKind.CaseBlock: return emitCaseBlock(node); + case SyntaxKind.NamespaceExportDeclaration: + return emitNamespaceExportDeclaration(node); case SyntaxKind.ImportEqualsDeclaration: return emitImportEqualsDeclaration(node); case SyntaxKind.ImportDeclaration: @@ -1886,6 +1888,12 @@ namespace ts { write(";"); } + function emitNamespaceExportDeclaration(node: NamespaceExportDeclaration) { + write("export as namespace "); + emit(node.name); + write(";"); + } + function emitNamedExports(node: NamedExports) { emitNamedImportsOrExports(node); } diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index cc7f89acfb8..d02aaecf333 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -345,6 +345,9 @@ namespace ts { case SyntaxKind.PropertyDeclaration: // TypeScript property declarations are elided. + + case SyntaxKind.NamespaceExportDeclaration: + // TypeScript namespace export declarations are elided. return undefined; case SyntaxKind.Constructor: diff --git a/src/harness/unittests/printer.ts b/src/harness/unittests/printer.ts index aedaacbf76c..a9af46b2780 100644 --- a/src/harness/unittests/printer.ts +++ b/src/harness/unittests/printer.ts @@ -131,6 +131,9 @@ namespace ts { // tslint:enable boolean-trivia printsCorrectly("class", {}, printer => printer.printNode(EmitHint.Unspecified, syntheticNode, sourceFile)); + + printsCorrectly("namespaceExportDeclaration", {}, printer => printer.printNode(EmitHint.Unspecified, createNamespaceExportDeclaration("B"), sourceFile)); + printsCorrectly("classWithOptionalMethodAndProperty", {}, printer => printer.printNode(EmitHint.Unspecified, classWithOptionalMethodAndProperty, sourceFile)); }); }); diff --git a/tests/baselines/reference/printerApi/printsNodeCorrectly.namespaceExportDeclaration.js b/tests/baselines/reference/printerApi/printsNodeCorrectly.namespaceExportDeclaration.js new file mode 100644 index 00000000000..725da0cef9f --- /dev/null +++ b/tests/baselines/reference/printerApi/printsNodeCorrectly.namespaceExportDeclaration.js @@ -0,0 +1 @@ +export as namespace B; \ No newline at end of file