Skip to content
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
25 changes: 22 additions & 3 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3267,9 +3267,12 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> 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;
Expand All @@ -3296,6 +3299,22 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for TSModuleDeclaration<'a> {
}
}

impl<const MINIFY: bool> Gen<MINIFY> 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<MINIFY> for TSModuleDeclarationName<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) {
match self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ input_file: crates/oxc_isolated_declarations/tests/fixtures/declare-global.ts
---
==================== .D.TS ====================

declare module global {}
declare global {}
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions tasks/coverage/transpile.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Mismatch: "declarationRestParameters.ts"

#### "declarationComputedPropertyNames.ts" ####
//// [declarationComputedPropertyNames.ts] ////
export module presentNs {
export namespace presentNs {
export const a = Symbol();
}
const aliasing = Symbol;
Expand Down Expand Up @@ -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;
Expand Down