Skip to content
Merged
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
34 changes: 33 additions & 1 deletion crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use oxc_span::{Atom, GetSpan, Ident, Span};
use oxc_syntax::{operator::UnaryOperator, scope::ScopeFlags};
use oxc_syntax::{operator::UnaryOperator, scope::ScopeFlags, symbol::SymbolId};

use crate::ast::*;

Expand Down Expand Up @@ -1324,6 +1324,38 @@ impl<'a> BindingPattern<'a> {
idents
}

fn append_symbol_ids(&self, symbol_ids: &mut std::vec::Vec<SymbolId>) {
match self {
Self::BindingIdentifier(ident) => {
symbol_ids.push(ident.symbol_id());
}
Self::AssignmentPattern(assign) => assign.left.append_symbol_ids(symbol_ids),
Self::ArrayPattern(pattern) => {
pattern
.elements
.iter()
.filter_map(|item| item.as_ref())
.for_each(|item| item.append_symbol_ids(symbol_ids));
if let Some(rest) = &pattern.rest {
rest.argument.append_symbol_ids(symbol_ids);
}
}
Self::ObjectPattern(pattern) => {
pattern.properties.iter().for_each(|item| item.value.append_symbol_ids(symbol_ids));
if let Some(rest) = &pattern.rest {
rest.argument.append_symbol_ids(symbol_ids);
}
}
}
}

/// Returns the [`SymbolId`]s of the bound identifiers in this binding pattern.
pub fn get_symbol_ids(&self) -> std::vec::Vec<SymbolId> {
let mut symbol_ids = vec![];
self.append_symbol_ids(&mut symbol_ids);
symbol_ids
}

/// Returns `true` if all binding identifiers in this pattern satisfy the given predicate.
///
/// This method is more efficient than [`BindingPattern::get_binding_identifiers`] followed by [`Iterator::all`]
Expand Down
Loading