Skip to content

Commit 7ee7634

Browse files
committed
fix(isolated-declarations): import statement disappears when import binding is referenced in nested typeof (#8476)
close: #8474
1 parent 7252cb0 commit 7ee7634

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

crates/oxc_isolated_declarations/src/scope.rs

+6
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,16 @@ impl<'a> Visit<'a> for ScopeTree<'a> {
110110
}
111111
}
112112

113+
// `typeof Value` or `typeof Value<Parameters>`
113114
fn visit_ts_type_query(&mut self, ty: &TSTypeQuery<'a>) {
114115
if let Some(type_name) = ty.expr_name.as_ts_type_name() {
115116
let ident = TSTypeName::get_identifier_reference(type_name);
116117
self.add_reference(ident.name.clone(), KindFlags::Value);
118+
// `typeof Type<Parameters>`
119+
// ^^^^^^^^^^^
120+
if let Some(type_parameters) = &ty.type_parameters {
121+
self.visit_ts_type_parameter_instantiation(type_parameters);
122+
}
117123
} else {
118124
walk_ts_type_query(self, ty);
119125
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { ModA } from 'mod';
2+
import { Variable } from 'constant';
3+
4+
export const Export: typeof ModA<typeof Variable> = 0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: crates/oxc_isolated_declarations/tests/mod.rs
3+
input_file: crates/oxc_isolated_declarations/tests/fixtures/typeof.ts
4+
---
5+
```
6+
==================== .D.TS ====================
7+
8+
import { ModA } from "mod";
9+
import { Variable } from "constant";
10+
export declare const Export: typeof ModA<typeof Variable>;

0 commit comments

Comments
 (0)