@@ -716,7 +716,9 @@ let rec push_negation (e : t) : t option =
716
716
- [(typeof x === "boolean" | "string" | "number") && (x === boolean/null/undefined/123/"hello")] -> [false]
717
717
- [(Array.isArray(x)) && (x === boolean/null/undefined/123/"hello")] -> [false]
718
718
719
- - [(typeof x === "boolean") && (x !== true/false)] -> unchanged
719
+ - [(typeof x === "boolean") && (x)] -> [(x == true)]
720
+ - [(typeof x === "boolean") && (!x)] -> [(x == false)]
721
+ - [(typeof x === "boolean") && (x !== true/false)] -> [(x == false/true)]
720
722
- [(typeof x === "string") && (x !== "abc")] -> unchanged
721
723
- [(typeof x === "number") && (x !== 123)] -> unchanged
722
724
- [(typeof x === "object") && (x !== null)] -> unchanged
@@ -861,14 +863,48 @@ let rec simplify_and ~n (e1 : t) (e2 : t) : t option =
861
863
( EqEqEq ,
862
864
{expression_desc = Typeof {expression_desc = Var ia}},
863
865
{expression_desc = Str {txt = " boolean" }} ),
864
- Bin ( NotEqEq , {expression_desc = Var ib}, {expression_desc = Bool _}) )
865
- | ( Bin ( NotEqEq , {expression_desc = Var ib}, {expression_desc = Bool _}) ,
866
+ Var ib )
867
+ | ( Var ib,
866
868
Bin
867
869
( EqEqEq ,
868
870
{expression_desc = Typeof {expression_desc = Var ia}},
869
871
{expression_desc = Str {txt = " boolean" }} ) )
870
872
when Js_op_util. same_vident ia ib ->
871
- None
873
+ Some
874
+ {
875
+ expression_desc =
876
+ Bin (EqEqEq , {expression_desc = Var ib; comment = None }, true_);
877
+ comment = None ;
878
+ }
879
+ | ( Bin
880
+ ( EqEqEq ,
881
+ {expression_desc = Typeof {expression_desc = Var ia}},
882
+ {expression_desc = Str {txt = " boolean" }} ),
883
+ Js_not {expression_desc = Var ib} )
884
+ | ( Js_not {expression_desc = Var ib},
885
+ Bin
886
+ ( EqEqEq ,
887
+ {expression_desc = Typeof {expression_desc = Var ia}},
888
+ {expression_desc = Str {txt = " boolean" }} ) )
889
+ when Js_op_util. same_vident ia ib ->
890
+ Some
891
+ {
892
+ expression_desc =
893
+ Bin (EqEqEq , {expression_desc = Var ib; comment = None }, false_);
894
+ comment = None ;
895
+ }
896
+ | ( Bin
897
+ ( EqEqEq ,
898
+ {expression_desc = Typeof {expression_desc = Var ia}},
899
+ {expression_desc = Str {txt = " boolean" }} ),
900
+ Bin (NotEqEq , {expression_desc = Var ib}, {expression_desc = Bool b}) )
901
+ | ( Bin (NotEqEq , {expression_desc = Var ib}, {expression_desc = Bool b}),
902
+ Bin
903
+ ( EqEqEq ,
904
+ {expression_desc = Typeof {expression_desc = Var ia}},
905
+ {expression_desc = Str {txt = " boolean" }} ) )
906
+ when Js_op_util. same_vident ia ib ->
907
+ Some {expression_desc = Bool (not b); comment = None }
872
908
| ( Bin
873
909
( EqEqEq ,
874
910
{expression_desc = Typeof {expression_desc = Var ia}},
0 commit comments