@@ -718,6 +718,10 @@ let rec push_negation (e : t) : t option =
718
718
- [(typeof x === "boolean" | "string" | "number") && (x !== boolean/null/undefined)] -> [typeof x === ...]
719
719
- [(Array.isArray(x)) && (x !== boolean/null/undefined)] -> [Array.isArray(x)]
720
720
721
+ Equality optimizations:
722
+ - [e && e] -> [e]
723
+ - [(x === boolean/null/undefined) && (x === boolean/null/undefined)] -> [false] (when not equal)
724
+
721
725
Note: The function preserves the semantics of the original expression while
722
726
attempting to reduce it to a simpler form. If no simplification is possible,
723
727
returns [None].
@@ -726,7 +730,6 @@ let rec simplify_and (e1 : t) (e2 : t) : t option =
726
730
if debug then
727
731
Printf. eprintf " simplify_and %s %s\n " (! string_of_expression e1)
728
732
(! string_of_expression e2);
729
-
730
733
match (e1.expression_desc, e2.expression_desc) with
731
734
| Bool false , _ -> Some false_
732
735
| _ , Bool false -> Some false_
@@ -735,39 +738,21 @@ let rec simplify_and (e1 : t) (e2 : t) : t option =
735
738
| Bin (And, a , b ), _ -> (
736
739
let ao = simplify_and a e2 in
737
740
let bo = simplify_and b e2 in
738
- if ao = None && bo = None then None
739
- else
740
- let a_ =
741
- match ao with
742
- | None -> a
743
- | Some a_ -> a_
744
- in
745
- let b_ =
746
- match bo with
747
- | None -> b
748
- | Some b_ -> b_
749
- in
741
+ match (ao, bo) with
742
+ | None , _ | _ , None -> None
743
+ | Some a_ , Some b_ -> (
750
744
match simplify_and a_ b_ with
751
745
| None -> Some {expression_desc = Bin (And , a_, b_); comment = None }
752
- | Some e -> Some e)
746
+ | Some e -> Some e))
753
747
| Bin (Or, a , b ), _ -> (
754
748
let ao = simplify_and a e2 in
755
749
let bo = simplify_and b e2 in
756
- if ao = None && bo = None then None
757
- else
758
- let a_ =
759
- match ao with
760
- | None -> a
761
- | Some a_ -> a_
762
- in
763
- let b_ =
764
- match bo with
765
- | None -> b
766
- | Some b_ -> b_
767
- in
750
+ match (ao, bo) with
751
+ | None , _ | _ , None -> None
752
+ | Some a_ , Some b_ -> (
768
753
match simplify_or a_ b_ with
769
754
| None -> Some {expression_desc = Bin (Or , a_, b_); comment = None }
770
- | Some e -> Some e)
755
+ | Some e -> Some e))
771
756
| ( Bin
772
757
( ((EqEqEq | NotEqEq ) as op1),
773
758
{expression_desc = Var i1},
@@ -882,6 +867,17 @@ let rec simplify_and (e1 : t) (e2 : t) : t option =
882
867
when Js_op_util. same_vident ia ib ->
883
868
Some {expression_desc = is_array; comment = None }
884
869
| x , y when x = y -> Some e1
870
+ | ( Bin
871
+ ( EqEqEq ,
872
+ {expression_desc = Var ia},
873
+ {expression_desc = Bool _ | Null | Undefined _} ),
874
+ Bin
875
+ ( EqEqEq ,
876
+ {expression_desc = Var ib},
877
+ {expression_desc = Bool _ | Null | Undefined _} ) )
878
+ when Js_op_util. same_vident ia ib ->
879
+ (* Note: case x = y is handled above *)
880
+ Some false_
885
881
| _ -> None
886
882
887
883
(* *
0 commit comments