fix(isolated-declarations): declare global {} should be kept even if it is not exported (#3956)

close: #3952
This commit is contained in:
Dunqing 2024-06-29 05:07:21 +00:00
parent 15ec254740
commit 31e4c3b33e
4 changed files with 23 additions and 0 deletions

View file

@ -824,6 +824,12 @@ pub enum TSModuleDeclarationKind {
Namespace,
}
impl TSModuleDeclarationKind {
pub fn is_global(self) -> bool {
matches!(self, TSModuleDeclarationKind::Global)
}
}
#[visited_node]
#[derive(Debug, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]

View file

@ -142,6 +142,11 @@ impl<'a> IsolatedDeclarations<'a> {
);
variable_transformed_indexes.push_back(Vec::default());
}
Declaration::TSModuleDeclaration(decl) => {
if decl.kind.is_global() {
transformed_indexes.push(new_stmts.len());
}
}
_ => {}
}
new_stmts.push(stmt);

View file

@ -0,0 +1,4 @@
declare global {
}
export {}

View file

@ -0,0 +1,8 @@
---
source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/declare-global.ts
---
==================== .D.TS ====================
declare module global {}
export {};