Skip to content

Commit e82bd5c

Browse files
committed
refactor(transformer/typescript): simplify TypeScriptAnnotations::has_value_reference method
1 parent 0a2fed4 commit e82bd5c

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

crates/oxc_transformer/src/typescript/annotations.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'a> Traverse<'a> for TypeScriptAnnotations<'a, '_> {
121121
if self.only_remove_type_imports {
122122
true
123123
} else {
124-
self.has_value_reference(&id.name, ctx)
124+
self.has_value_reference(id, ctx)
125125
}
126126
});
127127

@@ -597,27 +597,22 @@ impl<'a> TypeScriptAnnotations<'a, '_> {
597597
}
598598
}
599599

600-
pub fn has_value_reference(&self, name: &str, ctx: &TraverseCtx<'a>) -> bool {
601-
if let Some(symbol_id) = ctx.scoping().get_root_binding(name) {
602-
// `import T from 'mod'; const T = 1;` The T has a value redeclaration
603-
// `import T from 'mod'; type T = number;` The T has a type redeclaration
604-
// If the symbol is still a value symbol after SymbolFlags::Import is removed, then it's a value redeclaration.
605-
// That means the import is shadowed, and we can safely remove the import.
606-
let has_value_redeclaration =
607-
(ctx.scoping().symbol_flags(symbol_id) - SymbolFlags::Import).is_value();
608-
if has_value_redeclaration {
609-
return false;
610-
}
611-
if ctx
612-
.scoping()
613-
.get_resolved_references(symbol_id)
614-
.any(|reference| !reference.is_type())
615-
{
616-
return true;
617-
}
600+
fn has_value_reference(&self, id: &BindingIdentifier<'a>, ctx: &TraverseCtx<'a>) -> bool {
601+
let symbol_id = id.symbol_id();
602+
603+
// `import T from 'mod'; const T = 1;` The T has a value redeclaration
604+
// `import T from 'mod'; type T = number;` The T has a type redeclaration
605+
// If the symbol is still a value symbol after `SymbolFlags::Import` is removed, then it's a value redeclaration.
606+
// That means the import is shadowed, and we can safely remove the import.
607+
if (ctx.scoping().symbol_flags(symbol_id) - SymbolFlags::Import).is_value() {
608+
return false;
609+
}
610+
611+
if ctx.scoping().get_resolved_references(symbol_id).any(|reference| !reference.is_type()) {
612+
return true;
618613
}
619614

620-
self.is_jsx_imports(name)
615+
self.is_jsx_imports(&id.name)
621616
}
622617
}
623618

0 commit comments

Comments
 (0)