Skip to content

Commit

Permalink
fix(minifier): should not handle the strict operation for bool compar…
Browse files Browse the repository at this point in the history
…ison.
  • Loading branch information
7086cmd committed Oct 3, 2024
1 parent 120fdad commit 37a3238
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ impl<'a> PeepholeSubstituteAlternateSyntax {
if let Ancestor::BinaryExpressionRight(u) = parent {
!matches!(
u.operator(),
BinaryOperator::Addition | BinaryOperator::Instanceof | BinaryOperator::In
BinaryOperator::Addition // Other effect, like string concatenation.
| BinaryOperator::Instanceof // Relational operator.
| BinaryOperator::In
| BinaryOperator::StrictEquality // It checks type, so we should not fold.
| BinaryOperator::StrictInequality
)
} else {
false
Expand Down Expand Up @@ -383,6 +387,10 @@ mod test {
test("x == x instanceof false", "x == x instanceof !1");
test("x in x >> true", "x in x >> 1");
test("x == fake(false)", "x == fake(!1)");

// The following should not be folded.
test("x === true", "x === !0");
test("x !== false", "x !== !1");
}

#[test]
Expand Down

0 comments on commit 37a3238

Please sign in to comment.