Skip to content

Commit e29f35a

Browse files
authored
Don't change global keyword to namespace in transformModuleDeclaration (#1223)
1 parent 740d5bb commit e29f35a

17 files changed

+19
-108
lines changed

internal/transformers/declarations/transform.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ func (tx *DeclarationTransformer) transformModuleDeclaration(input *ast.ModuleDe
11671167
tx.needsDeclare = false
11681168
inner := input.Body
11691169
keyword := input.Keyword
1170-
if input.Name() == nil || !ast.IsStringLiteral(input.Name()) {
1170+
if keyword != ast.KindGlobalKeyword && (input.Name() == nil || !ast.IsStringLiteral(input.Name())) {
11711171
keyword = ast.KindNamespaceKeyword
11721172
}
11731173

testdata/baselines/reference/submodule/compiler/declarationEmitRetainsJsdocyComments.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,11 @@ export declare class Foo {
113113
*/
114114
bar(s: number): void;
115115
}
116-
declare namespace global {
116+
declare global {
117117
interface ExtFunc {
118118
/**
119119
* comment6
120120
*/
121121
someMethod(collection: any[]): boolean;
122122
}
123123
}
124-
export {};

testdata/baselines/reference/submodule/compiler/declarationEmitRetainsJsdocyComments.js.diff

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@
3838
-* comment5
3939
-*/
4040
-someMethod: any;
41-
-declare global {
42-
+declare namespace global {
41+
declare global {
4342
interface ExtFunc {
44-
/**
45-
* comment6
46-
@@= skipped -13, +8 lines =@@
47-
someMethod(collection: any[]): boolean;
48-
}
49-
}
50-
+export {};
43+
/**

testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal1.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ export declare class A {
3939
//// [f2.d.ts]
4040
import { A } from "./f1";
4141
// change the shape of Array<T>
42-
declare namespace global {
42+
declare global {
4343
interface Array<T> {
4444
getA(): A;
4545
}
4646
}
47-
export {};

testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal1.js.diff

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212
}
1313
//// [f2.d.ts]
1414
import { A } from "./f1";
15-
-declare global {
1615
+// change the shape of Array<T>
17-
+declare namespace global {
16+
declare global {
1817
interface Array<T> {
19-
getA(): A;
20-
}
21-
}
22-
+export {};
18+
getA(): A;

testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let y = x.getCountAsString().toLowerCase();
3535
export declare class A {
3636
}
3737
//// [f2.d.ts]
38-
declare namespace global {
38+
declare global {
3939
interface Array<T> {
4040
getCountAsString(): string;
4141
}

testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal2.js.diff

Lines changed: 0 additions & 11 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ let y = x.getCountAsString().toLowerCase();
4242
export declare class A {
4343
}
4444
//// [f2.d.ts]
45-
declare namespace global {
45+
declare global {
4646
interface Array<T> {
4747
getCountAsString(): string;
4848
}

testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal3.js.diff

Lines changed: 0 additions & 11 deletions
This file was deleted.

testdata/baselines/reference/submodule/compiler/moduleAugmentationGlobal4.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ require("./f2");
3030

3131

3232
//// [f1.d.ts]
33-
declare namespace global {
33+
declare global {
3434
interface Something {
3535
x: any;
3636
}
3737
}
3838
export {};
3939
//// [f2.d.ts]
40-
declare namespace global {
40+
declare global {
4141
interface Something {
4242
y: any;
4343
}

0 commit comments

Comments
 (0)