fix(isolated-declarations): import statement disappears when import binding is referenced in nested typeof (#8476)

close: #8474
This commit is contained in:
Dunqing 2025-01-14 05:27:17 +00:00
parent 7252cb0d77
commit 7ee7634f1e
3 changed files with 20 additions and 0 deletions

View file

@ -110,10 +110,16 @@ impl<'a> Visit<'a> for ScopeTree<'a> {
}
}
// `typeof Value` or `typeof Value<Parameters>`
fn visit_ts_type_query(&mut self, ty: &TSTypeQuery<'a>) {
if let Some(type_name) = ty.expr_name.as_ts_type_name() {
let ident = TSTypeName::get_identifier_reference(type_name);
self.add_reference(ident.name.clone(), KindFlags::Value);
// `typeof Type<Parameters>`
// ^^^^^^^^^^^
if let Some(type_parameters) = &ty.type_parameters {
self.visit_ts_type_parameter_instantiation(type_parameters);
}
} else {
walk_ts_type_query(self, ty);
}

View file

@ -0,0 +1,4 @@
import { ModA } from 'mod';
import { Variable } from 'constant';
export const Export: typeof ModA<typeof Variable> = 0;

View file

@ -0,0 +1,10 @@
---
source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/typeof.ts
---
```
==================== .D.TS ====================
import { ModA } from "mod";
import { Variable } from "constant";
export declare const Export: typeof ModA<typeof Variable>;