diff --git a/crates/oxc_transformer/src/typescript/annotations.rs b/crates/oxc_transformer/src/typescript/annotations.rs index 2dfe90dc81577..31075b35e4ec5 100644 --- a/crates/oxc_transformer/src/typescript/annotations.rs +++ b/crates/oxc_transformer/src/typescript/annotations.rs @@ -121,7 +121,7 @@ impl<'a> Traverse<'a> for TypeScriptAnnotations<'a, '_> { if self.only_remove_type_imports { true } else { - self.has_value_reference(&id.name, ctx) + self.has_value_reference(id, ctx) } }); @@ -597,27 +597,22 @@ impl<'a> TypeScriptAnnotations<'a, '_> { } } - pub fn has_value_reference(&self, name: &str, ctx: &TraverseCtx<'a>) -> bool { - if let Some(symbol_id) = ctx.scoping().get_root_binding(name) { - // `import T from 'mod'; const T = 1;` The T has a value redeclaration - // `import T from 'mod'; type T = number;` The T has a type redeclaration - // If the symbol is still a value symbol after SymbolFlags::Import is removed, then it's a value redeclaration. - // That means the import is shadowed, and we can safely remove the import. - let has_value_redeclaration = - (ctx.scoping().symbol_flags(symbol_id) - SymbolFlags::Import).is_value(); - if has_value_redeclaration { - return false; - } - if ctx - .scoping() - .get_resolved_references(symbol_id) - .any(|reference| !reference.is_type()) - { - return true; - } + fn has_value_reference(&self, id: &BindingIdentifier<'a>, ctx: &TraverseCtx<'a>) -> bool { + let symbol_id = id.symbol_id(); + + // `import T from 'mod'; const T = 1;` The T has a value redeclaration + // `import T from 'mod'; type T = number;` The T has a type redeclaration + // If the symbol is still a value symbol after `SymbolFlags::Import` is removed, then it's a value redeclaration. + // That means the import is shadowed, and we can safely remove the import. + if (ctx.scoping().symbol_flags(symbol_id) - SymbolFlags::Import).is_value() { + return false; + } + + if ctx.scoping().get_resolved_references(symbol_id).any(|reference| !reference.is_type()) { + return true; } - self.is_jsx_imports(name) + self.is_jsx_imports(&id.name) } }