From 28a5350280339621a5a6f13a4ad761820ccf3c46 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Fri, 1 Nov 2024 15:44:11 +0000 Subject: [PATCH] refactor(ast): `StaticMemberExpression::get_first_object` use loop instead of recursion --- crates/oxc_ast/src/ast_impl/js.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/crates/oxc_ast/src/ast_impl/js.rs b/crates/oxc_ast/src/ast_impl/js.rs index ad39dd06cf0b00..8a12938bceb7bc 100644 --- a/crates/oxc_ast/src/ast_impl/js.rs +++ b/crates/oxc_ast/src/ast_impl/js.rs @@ -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; } } }