Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ impl<'a> LatePeepholeOptimizations {
if let Some(param) = &catch.param {
if let BindingPatternKind::BindingIdentifier(ident) = &param.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;
}
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_semantic/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
Loading