diff --git a/crates/oxc_isolated_declarations/src/lib.rs b/crates/oxc_isolated_declarations/src/lib.rs index 9f3e519e3..a5cb746f7 100644 --- a/crates/oxc_isolated_declarations/src/lib.rs +++ b/crates/oxc_isolated_declarations/src/lib.rs @@ -325,6 +325,11 @@ impl<'a> IsolatedDeclarations<'a> { new_ast_stmts.push(Statement::ImportDeclaration(decl)); } } + Statement::TSModuleDeclaration(decl) => { + if decl.kind.is_global() || decl.id.is_string_literal() { + new_ast_stmts.push(Statement::TSModuleDeclaration(decl)); + } + } _ => {} } } diff --git a/crates/oxc_isolated_declarations/tests/fixtures/module-declaration.ts b/crates/oxc_isolated_declarations/tests/fixtures/module-declaration.ts new file mode 100644 index 000000000..f88da9d55 --- /dev/null +++ b/crates/oxc_isolated_declarations/tests/fixtures/module-declaration.ts @@ -0,0 +1,21 @@ +import 'foo'; +declare module 'foo' { + interface Foo {} + const foo = 42; +} + +declare global { + interface Bar {} + const bar = 42 ; +} + +// should not be emitted +module baz { + interface Baz {} + const baz = 42; +} + +declare module x { + interface Qux {} + const qux = 42; +} diff --git a/crates/oxc_isolated_declarations/tests/snapshots/module-declaration.snap b/crates/oxc_isolated_declarations/tests/snapshots/module-declaration.snap new file mode 100644 index 000000000..2c3ddd956 --- /dev/null +++ b/crates/oxc_isolated_declarations/tests/snapshots/module-declaration.snap @@ -0,0 +1,15 @@ +--- +source: crates/oxc_isolated_declarations/tests/mod.rs +input_file: crates/oxc_isolated_declarations/tests/fixtures/module-declaration.ts +--- +==================== .D.TS ==================== + +import "foo"; +declare module "foo" { + interface Foo {} + const foo = 42; +} +declare global { + interface Bar {} + const bar = 42; +}