Skip to content

Don't change global keyword to namespace in transformModuleDeclaration #1223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/transformers/declarations/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,11 @@ export declare class Foo {
*/
bar(s: number): void;
}
declare namespace global {
declare global {
interface ExtFunc {
/**
* comment6
*/
someMethod(collection: any[]): boolean;
}
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
/**
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ export declare class A {
//// [f2.d.ts]
import { A } from "./f1";
// change the shape of Array<T>
declare namespace global {
declare global {
interface Array<T> {
getA(): A;
}
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
}
//// [f2.d.ts]
import { A } from "./f1";
-declare global {
+// change the shape of Array<T>
+declare namespace global {
declare global {
interface Array<T> {
getA(): A;
}
}
+export {};
getA(): A;
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let y = x.getCountAsString().toLowerCase();
export declare class A {
}
//// [f2.d.ts]
declare namespace global {
declare global {
interface Array<T> {
getCountAsString(): string;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let y = x.getCountAsString().toLowerCase();
export declare class A {
}
//// [f2.d.ts]
declare namespace global {
declare global {
interface Array<T> {
getCountAsString(): string;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -75,4 +75,3 @@ declare namespace global {
}
import * as model from "./model";
export declare const func: (account: model.Account, acc2: model.Acc) => void;
export {};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ from(new MyObservable(42));


//// [symbolProperty61.d.ts]
declare namespace global {
declare global {
interface SymbolConstructor {
readonly obs: symbol;
}
Expand All @@ -64,4 +64,3 @@ export declare class MyObservable<T> {
constructor(_val: T);
subscribe(next: (val: T) => void): void;
}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -26,4 +20,4 @@
subscribe(next: (val: T) => void): void;
- [observable](): this;
}
export {};
-export {};