Merge pull request #18660 from Microsoft/globalAugmentationPrinter

Correctly print global augmentations
This commit is contained in:
Daniel Rosenwasser
2017-09-22 15:01:10 -07:00
committed by GitHub
4 changed files with 28 additions and 1 deletions

4
src/compiler/emitter.ts Normal file → Executable file
View File

@@ -1863,7 +1863,9 @@ namespace ts {
function emitModuleDeclaration(node: ModuleDeclaration) {
emitModifiers(node, node.modifiers);
write(node.flags & NodeFlags.Namespace ? "namespace " : "module ");
if (~node.flags & NodeFlags.GlobalAugmentation) {
write(node.flags & NodeFlags.Namespace ? "namespace " : "module ");
}
emit(node.name);
let body = node.body;

View File

@@ -110,6 +110,29 @@ namespace ts {
createSourceFile("source.ts", "", ScriptTarget.ES2015)
));
printsCorrectly("emptyGlobalAugmentation", {}, printer => printer.printNode(
EmitHint.Unspecified,
createModuleDeclaration(
/*decorators*/ undefined,
/*modifiers*/ [createToken(SyntaxKind.DeclareKeyword)],
createIdentifier("global"),
createModuleBlock(emptyArray),
NodeFlags.GlobalAugmentation),
createSourceFile("source.ts", "", ScriptTarget.ES2015)
));
printsCorrectly("emptyGlobalAugmentationWithNoDeclareKeyword", {}, printer => printer.printNode(
EmitHint.Unspecified,
createModuleDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
createIdentifier("global"),
createModuleBlock(emptyArray),
NodeFlags.GlobalAugmentation),
createSourceFile("source.ts", "", ScriptTarget.ES2015)
));
// https://github.com/Microsoft/TypeScript/issues/15971
printsCorrectly("classWithOptionalMethodAndProperty", {}, printer => printer.printNode(
EmitHint.Unspecified,

View File

@@ -0,0 +1 @@
declare global { }