mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(ast): StaticMemberExpression::get_first_object use loop instead of recursion (#7065)
Follow-on after #6969. Pure refactor. Loops are generally cheaper than recursion.
This commit is contained in:
parent
4012e6ba0c
commit
b0211a1f9e
1 changed files with 15 additions and 8 deletions
|
|
@ -512,16 +512,23 @@ impl<'a> ComputedMemberExpression<'a> {
|
|||
impl<'a> StaticMemberExpression<'a> {
|
||||
#[allow(missing_docs)]
|
||||
pub fn get_first_object(&self) -> &Expression<'a> {
|
||||
match &self.object {
|
||||
Expression::StaticMemberExpression(member) => member.get_first_object(),
|
||||
Expression::ChainExpression(chain) => {
|
||||
if let ChainElement::StaticMemberExpression(expr) = &chain.expression {
|
||||
expr.get_first_object()
|
||||
} else {
|
||||
&self.object
|
||||
let mut object = &self.object;
|
||||
loop {
|
||||
match object {
|
||||
Expression::StaticMemberExpression(member) => {
|
||||
object = &member.object;
|
||||
continue;
|
||||
}
|
||||
Expression::ChainExpression(chain) => {
|
||||
if let ChainElement::StaticMemberExpression(member) = &chain.expression {
|
||||
object = &member.object;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
_ => &self.object,
|
||||
|
||||
return object;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue