diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index 647f516357..075c3d6644 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -1167,7 +1167,7 @@ func (tx *DeclarationTransformer) transformModuleDeclaration(input *ast.ModuleDe tx.needsDeclare = false inner := input.Body keyword := input.Keyword - if input.Name() == nil || !ast.IsStringLiteral(input.Name()) { + if keyword != ast.KindGlobalKeyword && (input.Name() == nil || !ast.IsStringLiteral(input.Name())) { keyword = ast.KindNamespaceKeyword } diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitRetainsJsdocyComments.js b/testdata/baselines/reference/submodule/compiler/declarationEmitRetainsJsdocyComments.js index a1bcf4f1ac..6211ab2063 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitRetainsJsdocyComments.js +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitRetainsJsdocyComments.js @@ -113,7 +113,7 @@ export declare class Foo { */ bar(s: number): void; } -declare namespace global { +declare global { interface ExtFunc { /** * comment6 @@ -121,4 +121,3 @@ declare namespace global { someMethod(collection: any[]): boolean; } } -export {}; diff --git a/testdata/baselines/reference/submodule/compiler/declarationEmitRetainsJsdocyComments.js.diff b/testdata/baselines/reference/submodule/compiler/declarationEmitRetainsJsdocyComments.js.diff index f34f7272b8..31a3a76f25 100644 --- a/testdata/baselines/reference/submodule/compiler/declarationEmitRetainsJsdocyComments.js.diff +++ b/testdata/baselines/reference/submodule/compiler/declarationEmitRetainsJsdocyComments.js.diff @@ -38,13 +38,6 @@ -* comment5 -*/ -someMethod: any; --declare global { -+declare namespace global { + declare global { interface ExtFunc { - /** - * comment6 -@@= skipped -13, +8 lines =@@ - someMethod(collection: any[]): boolean; - } - } -+export {}; \ No newline at end of file + /** \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal1.js b/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal1.js index 6640282317..32336d5912 100644 --- a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal1.js +++ b/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal1.js @@ -39,9 +39,8 @@ export declare class A { //// [f2.d.ts] import { A } from "./f1"; // change the shape of Array -declare namespace global { +declare global { interface Array { getA(): A; } } -export {}; diff --git a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal1.js.diff b/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal1.js.diff index 4148f7e8d3..76a1064f43 100644 --- a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal1.js.diff +++ b/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal1.js.diff @@ -12,11 +12,7 @@ } //// [f2.d.ts] import { A } from "./f1"; --declare global { +// change the shape of Array -+declare namespace global { + declare global { interface Array { - getA(): A; - } - } -+export {}; \ No newline at end of file + getA(): A; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal2.js b/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal2.js index a1fee14aaf..35074ca47e 100644 --- a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal2.js +++ b/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal2.js @@ -35,7 +35,7 @@ let y = x.getCountAsString().toLowerCase(); export declare class A { } //// [f2.d.ts] -declare namespace global { +declare global { interface Array { getCountAsString(): string; } diff --git a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal2.js.diff b/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal2.js.diff deleted file mode 100644 index 7d0a9df9b9..0000000000 --- a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal2.js.diff +++ /dev/null @@ -1,11 +0,0 @@ ---- old.moduleAugmentationGlobal2.js -+++ new.moduleAugmentationGlobal2.js -@@= skipped -34, +34 lines =@@ - export declare class A { - } - //// [f2.d.ts] --declare global { -+declare namespace global { - interface Array { - getCountAsString(): string; - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal3.js b/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal3.js index 01fdfd85cd..1f2b4c1596 100644 --- a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal3.js +++ b/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal3.js @@ -42,7 +42,7 @@ let y = x.getCountAsString().toLowerCase(); export declare class A { } //// [f2.d.ts] -declare namespace global { +declare global { interface Array { getCountAsString(): string; } diff --git a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal3.js.diff b/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal3.js.diff deleted file mode 100644 index 76d60358de..0000000000 --- a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal3.js.diff +++ /dev/null @@ -1,11 +0,0 @@ ---- old.moduleAugmentationGlobal3.js -+++ new.moduleAugmentationGlobal3.js -@@= skipped -41, +41 lines =@@ - export declare class A { - } - //// [f2.d.ts] --declare global { -+declare namespace global { - interface Array { - getCountAsString(): string; - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal4.js b/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal4.js index 96951df31d..4124a7e4f3 100644 --- a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal4.js +++ b/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal4.js @@ -30,14 +30,14 @@ require("./f2"); //// [f1.d.ts] -declare namespace global { +declare global { interface Something { x: any; } } export {}; //// [f2.d.ts] -declare namespace global { +declare global { interface Something { y: any; } diff --git a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal4.js.diff b/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal4.js.diff deleted file mode 100644 index 4e3a3c9e63..0000000000 --- a/testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal4.js.diff +++ /dev/null @@ -1,19 +0,0 @@ ---- old.moduleAugmentationGlobal4.js -+++ new.moduleAugmentationGlobal4.js -@@= skipped -29, +29 lines =@@ - - - //// [f1.d.ts] --declare global { -+declare namespace global { - interface Something { - x: any; - } - } - export {}; - //// [f2.d.ts] --declare global { -+declare namespace global { - interface Something { - y: any; - } \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.js b/testdata/baselines/reference/submodule/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.js index 407de174f9..05a55dc77c 100644 --- a/testdata/baselines/reference/submodule/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.js +++ b/testdata/baselines/reference/submodule/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.js @@ -65,7 +65,7 @@ export { Account2 as Acc }; //// [index.d.ts] export * from "./account"; //// [index.d.ts] -declare namespace global { +declare global { interface Account { someProp: number; } @@ -75,4 +75,3 @@ declare namespace global { } import * as model from "./model"; export declare const func: (account: model.Account, acc2: model.Acc) => void; -export {}; diff --git a/testdata/baselines/reference/submodule/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.js.diff b/testdata/baselines/reference/submodule/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.js.diff deleted file mode 100644 index 0edec3dea1..0000000000 --- a/testdata/baselines/reference/submodule/compiler/moduleDeclarationExportStarShadowingGlobalIsNameable.js.diff +++ /dev/null @@ -1,16 +0,0 @@ ---- old.moduleDeclarationExportStarShadowingGlobalIsNameable.js -+++ new.moduleDeclarationExportStarShadowingGlobalIsNameable.js -@@= skipped -64, +64 lines =@@ - //// [index.d.ts] - export * from "./account"; - //// [index.d.ts] --declare global { -+declare namespace global { - interface Account { - someProp: number; - } -@@= skipped -10, +10 lines =@@ - } - import * as model from "./model"; - export declare const func: (account: model.Account, acc2: model.Acc) => void; -+export {}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/leaveOptionalParameterAsWritten.js b/testdata/baselines/reference/submodule/conformance/leaveOptionalParameterAsWritten.js index 40858d9de3..aa0c0ca22d 100644 --- a/testdata/baselines/reference/submodule/conformance/leaveOptionalParameterAsWritten.js +++ b/testdata/baselines/reference/submodule/conformance/leaveOptionalParameterAsWritten.js @@ -24,13 +24,12 @@ export interface Foo { } //// [b.d.ts] import * as a from "./a"; -declare namespace global { +declare global { namespace teams { namespace calling { export import Foo = a.Foo; } } } -export {}; //// [c.d.ts] export declare const bar: (p?: import("./a").Foo | undefined) => void; diff --git a/testdata/baselines/reference/submodule/conformance/leaveOptionalParameterAsWritten.js.diff b/testdata/baselines/reference/submodule/conformance/leaveOptionalParameterAsWritten.js.diff index 4e943d44ef..9b5671baa5 100644 --- a/testdata/baselines/reference/submodule/conformance/leaveOptionalParameterAsWritten.js.diff +++ b/testdata/baselines/reference/submodule/conformance/leaveOptionalParameterAsWritten.js.diff @@ -1,20 +1,10 @@ --- old.leaveOptionalParameterAsWritten.js +++ new.leaveOptionalParameterAsWritten.js -@@= skipped -23, +23 lines =@@ - } - //// [b.d.ts] - import * as a from "./a"; --declare global { -+declare namespace global { - namespace teams { - namespace calling { - export import Foo = a.Foo; - } +@@= skipped -31, +31 lines =@@ } } --//// [c.d.ts] + //// [c.d.ts] -type Foo = teams.calling.Foo; -export declare const bar: (p?: Foo) => void; - export {}; -+//// [c.d.ts] +-export {}; +export declare const bar: (p?: import("./a").Foo | undefined) => void; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/symbolProperty61.js b/testdata/baselines/reference/submodule/conformance/symbolProperty61.js index 4659f8ec8c..3ed2223c95 100644 --- a/testdata/baselines/reference/submodule/conformance/symbolProperty61.js +++ b/testdata/baselines/reference/submodule/conformance/symbolProperty61.js @@ -53,7 +53,7 @@ from(new MyObservable(42)); //// [symbolProperty61.d.ts] -declare namespace global { +declare global { interface SymbolConstructor { readonly obs: symbol; } @@ -64,4 +64,3 @@ export declare class MyObservable { constructor(_val: T); subscribe(next: (val: T) => void): void; } -export {}; diff --git a/testdata/baselines/reference/submodule/conformance/symbolProperty61.js.diff b/testdata/baselines/reference/submodule/conformance/symbolProperty61.js.diff index 5f2bd9e531..d108f7ff87 100644 --- a/testdata/baselines/reference/submodule/conformance/symbolProperty61.js.diff +++ b/testdata/baselines/reference/submodule/conformance/symbolProperty61.js.diff @@ -8,13 +8,7 @@ constructor(_val) { this._val = _val; } -@@= skipped -17, +18 lines =@@ - - - //// [symbolProperty61.d.ts] --declare global { -+declare namespace global { - interface SymbolConstructor { +@@= skipped -22, +23 lines =@@ readonly obs: symbol; } } @@ -26,4 +20,4 @@ subscribe(next: (val: T) => void): void; - [observable](): this; } - export {}; \ No newline at end of file +-export {}; \ No newline at end of file