From 600ba20f3e4512df3e0bdbb31f86920144c56f68 Mon Sep 17 00:00:00 2001 From: Ethan Goh <7086cmd@gmail.com> Date: Wed, 2 Oct 2024 07:50:35 +0800 Subject: [PATCH] refactor: use `parent()` instead of find. --- .../peephole_substitute_alternate_syntax.rs | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs b/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs index 45816d051100a0..ef288f787b086c 100644 --- a/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_substitute_alternate_syntax.rs @@ -171,24 +171,17 @@ impl<'a> PeepholeSubstituteAlternateSyntax { fn compress_boolean(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) -> bool { let Expression::BooleanLiteral(lit) = expr else { return false }; if self.options.booleans && !self.in_define_export { - let no_unary = ctx - .ancestry - .ancestors() - .map(|a| { - if let Ancestor::BinaryExpressionRight(r) = a { - let operator = r.operator(); - !matches!( - operator, - BinaryOperator::Addition - | BinaryOperator::Instanceof - | BinaryOperator::In - ) - } else { - false - } - }) - .next() - .unwrap_or(false); + let parent = ctx.ancestry.parent(); + let no_unary = { + if let Ancestor::BinaryExpressionRight(u) = parent { + !matches!( + u.operator(), + BinaryOperator::Addition | BinaryOperator::Instanceof | BinaryOperator::In + ) + } else { + false + } + }; // XOR: We should use `!neg` when it is not in binary expression. let num = ctx.ast.expression_numeric_literal( SPAN,