@@ -711,7 +711,10 @@ let rec push_negation (e : t) : t option =
711
711
712
712
Type check optimizations:
713
713
- [(typeof x === "boolean") && (x === true/false)] -> [x === true/false]
714
- - [(typeof x === "string" || Array.isArray(x)) && (x === boolean/null/undefined)] -> [false]
714
+ - [(typeof x === "string") && (x === boolean/null/undefined)] -> [false]
715
+ - [(Array.isArray(x)) && (x === boolean/null/undefined)] -> [false]
716
+
717
+ - TODO: [(typeof x === "boolean") && (x !== null)] -> [typeof x === "boolean"]
715
718
716
719
Note: The function preserves the semantics of the original expression while
717
720
attempting to reduce it to a simpler form. If no simplification is possible,
@@ -790,14 +793,7 @@ let rec simplify_and (e1 : t) (e2 : t) : t option =
790
793
Some {expression_desc = b; comment = None }
791
794
| ( Bin
792
795
( EqEqEq ,
793
- {
794
- expression_desc =
795
- ( Typeof {expression_desc = Var ia}
796
- | Call
797
- ( {expression_desc = Str {txt = " Array.isArray" }},
798
- [{expression_desc = Var ia}],
799
- _ ) );
800
- },
796
+ {expression_desc = Typeof {expression_desc = Var ia}},
801
797
{expression_desc = Str {txt = " boolean" | " string" }} ),
802
798
Bin
803
799
( EqEqEq ,
@@ -809,18 +805,29 @@ let rec simplify_and (e1 : t) (e2 : t) : t option =
809
805
{expression_desc = Bool _ | Null | Undefined _} ),
810
806
Bin
811
807
( EqEqEq ,
812
- {
813
- expression_desc =
814
- ( Typeof {expression_desc = Var ia}
815
- | Call
816
- ( {expression_desc = Str {txt = " Array.isArray" }},
817
- [{expression_desc = Var ia}],
818
- _ ) );
819
- },
808
+ {expression_desc = Typeof {expression_desc = Var ia}},
820
809
{expression_desc = Str {txt = " boolean" | " string" }} ) )
821
810
when Js_op_util. same_vident ia ib ->
822
811
(* Note: case boolean / Bool _ is handled above *)
823
812
Some false_
813
+ | ( Call
814
+ ( {expression_desc = Str {txt = " Array.isArray" }},
815
+ [{expression_desc = Var ia}],
816
+ _ ),
817
+ Bin
818
+ ( EqEqEq ,
819
+ {expression_desc = Var ib},
820
+ {expression_desc = Bool _ | Null | Undefined _} ) )
821
+ | ( Bin
822
+ ( EqEqEq ,
823
+ {expression_desc = Var ib},
824
+ {expression_desc = Bool _ | Null | Undefined _} ),
825
+ Call
826
+ ( {expression_desc = Str {txt = " Array.isArray" }},
827
+ [{expression_desc = Var ia}],
828
+ _ ) )
829
+ when Js_op_util. same_vident ia ib ->
830
+ Some false_
824
831
| _ -> None
825
832
826
833
(* *
0 commit comments