diff --git a/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs b/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs index 996252bec7c2e..dac7884de46d6 100644 --- a/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs +++ b/crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs @@ -1076,7 +1076,7 @@ impl<'a> LatePeepholeOptimizations { if let Some(param) = &catch.param { if let BindingPatternKind::BindingIdentifier(ident) = ¶m.pattern.kind { if catch.body.body.is_empty() - || ctx.symbols().get_resolved_references(ident.symbol_id()).count() == 0 + || !ctx.symbols().symbol_is_used(ident.symbol_id()) { catch.param = None; } diff --git a/crates/oxc_semantic/src/symbol.rs b/crates/oxc_semantic/src/symbol.rs index 5e20a14191992..1b9ff752b6cd5 100644 --- a/crates/oxc_semantic/src/symbol.rs +++ b/crates/oxc_semantic/src/symbol.rs @@ -297,6 +297,11 @@ impl SymbolTable { } } + /// Get whether a symbol is used (i.e. read or written after declaration). + pub fn symbol_is_used(&self, symbol_id: SymbolId) -> bool { + self.get_resolved_references(symbol_id).count() > 0 + } + /// Add a reference to a symbol. pub fn add_resolved_reference(&mut self, symbol_id: SymbolId, reference_id: ReferenceId) { self.inner.with_dependent_mut(|_allocator, inner| {