fix(isolated_declarations): Always emit module declarations that perform augmentation (#4919)

Fixes https://github.com/oxc-project/oxc/issues/4607

Co-authored-by: MichaelMitchell-at <=>
This commit is contained in:
michaelm 2024-08-15 12:39:28 -04:00 committed by GitHub
parent 1eb59d2b5e
commit b3ec9e50bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 0 deletions

View file

@ -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));
}
}
_ => {}
}
}

View file

@ -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;
}

View file

@ -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;
}