Skip to content

Commit

Permalink
refactor: use parent() instead of find.
Browse files Browse the repository at this point in the history
  • Loading branch information
7086cmd authored and Boshen committed Oct 2, 2024
1 parent e557a7f commit 600ba20
Showing 1 changed file with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 600ba20

Please sign in to comment.