From f0ebcb15f9e720bee5a71cb170123f1a9cb9ec76 Mon Sep 17 00:00:00 2001 From: MichaelMitchell-at <=> Date: Thu, 15 Aug 2024 05:31:35 -0400 Subject: [PATCH] fix(isolated_declarations): Always emit module declarations that perform augmentation --- crates/oxc_isolated_declarations/src/lib.rs | 5 +++++ .../tests/fixtures/module-declaration.ts | 21 +++++++++++++++++++ .../tests/snapshots/module-declaration.snap | 15 +++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 crates/oxc_isolated_declarations/tests/fixtures/module-declaration.ts create mode 100644 crates/oxc_isolated_declarations/tests/snapshots/module-declaration.snap diff --git a/crates/oxc_isolated_declarations/src/lib.rs b/crates/oxc_isolated_declarations/src/lib.rs index 8485e01d03833b..c1813b03e53bff 100644 --- a/crates/oxc_isolated_declarations/src/lib.rs +++ b/crates/oxc_isolated_declarations/src/lib.rs @@ -314,6 +314,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 00000000000000..f88da9d55f95c1 --- /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 00000000000000..2c3ddd956960fb --- /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; +}