Skip to content

Commit 92b7dcf

Browse files
Merge pull request #18660 from Microsoft/globalAugmentationPrinter
Correctly print global augmentations
2 parents 5f4436d + 555718e commit 92b7dcf

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/compiler/emitter.ts

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,9 @@ namespace ts {
18631863

18641864
function emitModuleDeclaration(node: ModuleDeclaration) {
18651865
emitModifiers(node, node.modifiers);
1866-
write(node.flags & NodeFlags.Namespace ? "namespace " : "module ");
1866+
if (~node.flags & NodeFlags.GlobalAugmentation) {
1867+
write(node.flags & NodeFlags.Namespace ? "namespace " : "module ");
1868+
}
18671869
emit(node.name);
18681870

18691871
let body = node.body;

src/harness/unittests/printer.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,29 @@ namespace ts {
110110
createSourceFile("source.ts", "", ScriptTarget.ES2015)
111111
));
112112

113+
114+
printsCorrectly("emptyGlobalAugmentation", {}, printer => printer.printNode(
115+
EmitHint.Unspecified,
116+
createModuleDeclaration(
117+
/*decorators*/ undefined,
118+
/*modifiers*/ [createToken(SyntaxKind.DeclareKeyword)],
119+
createIdentifier("global"),
120+
createModuleBlock(emptyArray),
121+
NodeFlags.GlobalAugmentation),
122+
createSourceFile("source.ts", "", ScriptTarget.ES2015)
123+
));
124+
125+
printsCorrectly("emptyGlobalAugmentationWithNoDeclareKeyword", {}, printer => printer.printNode(
126+
EmitHint.Unspecified,
127+
createModuleDeclaration(
128+
/*decorators*/ undefined,
129+
/*modifiers*/ undefined,
130+
createIdentifier("global"),
131+
createModuleBlock(emptyArray),
132+
NodeFlags.GlobalAugmentation),
133+
createSourceFile("source.ts", "", ScriptTarget.ES2015)
134+
));
135+
113136
// https://github.com/Microsoft/TypeScript/issues/15971
114137
printsCorrectly("classWithOptionalMethodAndProperty", {}, printer => printer.printNode(
115138
EmitHint.Unspecified,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare global { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global { }

0 commit comments

Comments
 (0)