Skip to content

Commit

Permalink
perf(transformer/class-properties): replace recursion with loop
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Dec 4, 2024
1 parent c523ccb commit 8fd9090
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions crates/oxc_transformer/src/es2022/class_properties/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1216,20 +1216,35 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
/// Recursively check if the expression has optional expression.
#[inline]
fn has_optional_expression(expr: &Expression<'a>) -> bool {
match expr {
Expression::CallExpression(call) => {
call.optional || Self::has_optional_expression(call.callee.get_inner_expression())
}
Expression::StaticMemberExpression(member) => {
member.optional || Self::has_optional_expression(&member.object)
}
Expression::ComputedMemberExpression(member) => {
member.optional || Self::has_optional_expression(&member.object)
}
Expression::PrivateFieldExpression(member) => {
member.optional || Self::has_optional_expression(&member.object)
let mut expr = expr;
loop {
match expr {
Expression::CallExpression(call) => {
if call.optional {
return true;
}
expr = call.callee.get_inner_expression();
}
Expression::StaticMemberExpression(member) => {
if member.optional {
return true;
}
expr = &member.object;
}
Expression::ComputedMemberExpression(member) => {
if member.optional {
return true;
}
expr = &member.object;
}
Expression::PrivateFieldExpression(member) => {
if member.optional {
return true;
}
expr = &member.object;
}
_ => return false,
}
_ => false,
}
}

Expand Down

0 comments on commit 8fd9090

Please sign in to comment.