Skip to content

Commit 979295b

Browse files
Force 'declare' modifiers and correct global augmentation emit.
1 parent 764af0e commit 979295b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/compiler/emitter.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,8 +1862,19 @@ namespace ts {
18621862
}
18631863

18641864
function emitModuleDeclaration(node: ModuleDeclaration) {
1865-
emitModifiers(node, node.modifiers);
1866-
write(node.flags & NodeFlags.Namespace ? "namespace " : "module ");
1865+
if (node.flags & NodeFlags.GlobalAugmentation) {
1866+
if (!hasModifier(node, ModifierFlags.Ambient)) {
1867+
// Always emit a 'declare' keyword in case it wasn't provided by a factory function call.
1868+
write("declare ");
1869+
}
1870+
else {
1871+
emitModifiers(node, node.modifiers);
1872+
}
1873+
}
1874+
else {
1875+
emitModifiers(node, node.modifiers);
1876+
write(node.flags & NodeFlags.Namespace ? "namespace " : "module ");
1877+
}
18671878
emit(node.name);
18681879

18691880
let body = node.body;

0 commit comments

Comments
 (0)