@@ -728,6 +728,8 @@ let rec push_negation (e : t) : t option =
728
728
Equality optimizations:
729
729
- [e && e] -> [e]
730
730
- [(x === boolean/null/undefined/123/"hello") && (x === boolean/null/undefined/123/"hello")] -> [false] (when not equal)
731
+ - [(x === boolean/null/undefined/123/"hello") && (x !== boolean/null/undefined/123/"hello")] -> [false] (when equal)
732
+ - [(x === boolean/null/undefined/123/"hello") && (x !== boolean/null/undefined/123/"hello")] -> [(x === ...)] (when not equal)
731
733
732
734
Note: The function preserves the semantics of the original expression while
733
735
attempting to reduce it to a simpler form. If no simplification is possible,
@@ -763,6 +765,10 @@ let rec simplify_and ~n (e1 : t) (e2 : t) : t option =
763
765
let ao = simplify_and ~n: (n + 1 ) a e2 in
764
766
let bo = simplify_and ~n: (n + 1 ) b e2 in
765
767
match (ao, bo) with
768
+ | Some {expression_desc = Bool false } , None ->
769
+ Some {expression_desc = Bin (And , b, e2); comment = None }
770
+ | None , Some {expression_desc = Bool false } ->
771
+ Some {expression_desc = Bin (And , a, e2); comment = None }
766
772
| None , _ | _ , None -> (
767
773
match simplify_or ~n: (n + 1 ) a b with
768
774
| None -> None
@@ -1005,6 +1011,18 @@ let rec simplify_and ~n (e1 : t) (e2 : t) : t option =
1005
1011
when Js_op_util. same_vident ia ib ->
1006
1012
(* Note: case x = y is handled above *)
1007
1013
Some false_
1014
+ | ( Bin
1015
+ ( ((EqEqEq | NotEqEq ) as op1),
1016
+ {expression_desc = Var ia},
1017
+ ({expression_desc = Bool _ | Null | Undefined _ | Number _ | Str _}
1018
+ as v1) ),
1019
+ Bin
1020
+ ( ((EqEqEq | NotEqEq ) as op2),
1021
+ {expression_desc = Var ib},
1022
+ ({expression_desc = Bool _ | Null | Undefined _ | Number _ | Str _}
1023
+ as v2) ) )
1024
+ when Js_op_util. same_vident ia ib && op1 != op2 ->
1025
+ if v1 = v2 then Some false_ else if op1 = EqEqEq then Some e1 else Some e2
1008
1026
| _ -> None
1009
1027
in
1010
1028
(if debug then
0 commit comments