From bd1141da67467e5c588351c42133278552ff3e0c Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Sun, 30 Jun 2024 11:34:04 +0000 Subject: [PATCH] fix(isolated-declarations): if declarations is referenced in `declare global` then keep it (#3982) close: #3981 --- crates/oxc_isolated_declarations/src/lib.rs | 1 + .../tests/fixtures/declare-global.ts | 7 +++++++ .../tests/snapshots/declare-global.snap | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/oxc_isolated_declarations/src/lib.rs b/crates/oxc_isolated_declarations/src/lib.rs index b6796334e42b1..9799618bbdf14 100644 --- a/crates/oxc_isolated_declarations/src/lib.rs +++ b/crates/oxc_isolated_declarations/src/lib.rs @@ -144,6 +144,7 @@ impl<'a> IsolatedDeclarations<'a> { } Declaration::TSModuleDeclaration(decl) => { if decl.kind.is_global() { + self.scope.visit_ts_module_declaration(decl); transformed_indexes.push(new_stmts.len()); } } diff --git a/crates/oxc_isolated_declarations/tests/fixtures/declare-global.ts b/crates/oxc_isolated_declarations/tests/fixtures/declare-global.ts index c271fa55e7a99..fd994c73dcb10 100644 --- a/crates/oxc_isolated_declarations/tests/fixtures/declare-global.ts +++ b/crates/oxc_isolated_declarations/tests/fixtures/declare-global.ts @@ -1,4 +1,11 @@ +function MyFunction() { + return 'here is my function' +} + declare global { + interface Window { + MyFunction: typeof MyFunction + } } export {} \ No newline at end of file diff --git a/crates/oxc_isolated_declarations/tests/snapshots/declare-global.snap b/crates/oxc_isolated_declarations/tests/snapshots/declare-global.snap index 51bbc0340e3e8..c62c684d53213 100644 --- a/crates/oxc_isolated_declarations/tests/snapshots/declare-global.snap +++ b/crates/oxc_isolated_declarations/tests/snapshots/declare-global.snap @@ -4,5 +4,10 @@ input_file: crates/oxc_isolated_declarations/tests/fixtures/declare-global.ts --- ==================== .D.TS ==================== -declare global {} +declare function MyFunction(): string; +declare global { + interface Window { + MyFunction: typeof MyFunction; + } +} export {};