diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 46d9adb580ecf..3b80d465203a1 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -3267,9 +3267,12 @@ impl<'a, const MINIFY: bool> Gen for TSModuleDeclaration<'a> { if self.declare { p.print_str(b"declare "); } - p.print_str(b"module"); - p.print_space_before_identifier(); - self.id.gen(p, ctx); + self.kind.gen(p, ctx); + // If the kind is global, then the id is also `global`, so we don't need to print it + if !self.kind.is_global() { + p.print_space_before_identifier(); + self.id.gen(p, ctx); + } if let Some(body) = &self.body { let mut body = body; @@ -3296,6 +3299,22 @@ impl<'a, const MINIFY: bool> Gen for TSModuleDeclaration<'a> { } } +impl Gen for TSModuleDeclarationKind { + fn gen(&self, p: &mut Codegen<{ MINIFY }>, _: Context) { + match self { + TSModuleDeclarationKind::Global => { + p.print_str(b"global"); + } + TSModuleDeclarationKind::Module => { + p.print_str(b"module"); + } + TSModuleDeclarationKind::Namespace => { + p.print_str(b"namespace"); + } + } + } +} + impl<'a, const MINIFY: bool> Gen for TSModuleDeclarationName<'a> { fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) { match self { diff --git a/crates/oxc_isolated_declarations/tests/snapshots/declare-global.snap b/crates/oxc_isolated_declarations/tests/snapshots/declare-global.snap index 3b9bfaca72c1c..51bbc0340e3e8 100644 --- a/crates/oxc_isolated_declarations/tests/snapshots/declare-global.snap +++ b/crates/oxc_isolated_declarations/tests/snapshots/declare-global.snap @@ -4,5 +4,5 @@ input_file: crates/oxc_isolated_declarations/tests/fixtures/declare-global.ts --- ==================== .D.TS ==================== -declare module global {} +declare global {} export {}; diff --git a/crates/oxc_isolated_declarations/tests/snapshots/expando-function.snap b/crates/oxc_isolated_declarations/tests/snapshots/expando-function.snap index 9f41e74cc5f6c..f62c6293d980c 100644 --- a/crates/oxc_isolated_declarations/tests/snapshots/expando-function.snap +++ b/crates/oxc_isolated_declarations/tests/snapshots/expando-function.snap @@ -6,7 +6,7 @@ input_file: crates/oxc_isolated_declarations/tests/fixtures/expando-function.ts export declare function foo(): void; export declare const bar: () => void; -export declare module NS { +export declare namespace NS { export const goo: () => void; } diff --git a/tasks/coverage/transpile.snap b/tasks/coverage/transpile.snap index 9a23c816bf854..c9735e00fc17b 100644 --- a/tasks/coverage/transpile.snap +++ b/tasks/coverage/transpile.snap @@ -9,7 +9,7 @@ Mismatch: "declarationRestParameters.ts" #### "declarationComputedPropertyNames.ts" #### //// [declarationComputedPropertyNames.ts] //// -export module presentNs { +export namespace presentNs { export const a = Symbol(); } const aliasing = Symbol; @@ -67,7 +67,7 @@ export const D = { }; //// [declarationComputedPropertyNames.d.ts] //// -export declare module presentNs { +export declare namespace presentNs { export const a: unknown; } declare const aliasing: unknown;