@@ -711,10 +711,11 @@ 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") && (x === boolean/null/undefined)] -> [false]
714
+ - [(typeof x ==="boolean" | "string" | "number ") && (x === boolean/null/undefined)] -> [false]
715
715
- [(Array.isArray(x)) && (x === boolean/null/undefined)] -> [false]
716
716
717
- - TODO: [(typeof x === "boolean") && (x !== null)] -> [typeof x === "boolean"]
717
+ - [(typeof x === "boolean") && (x !== true/false)] -> unchanged
718
+ - [(typeof x === "boolean" | "string" | "number") && (x !== boolean/null/undefined)] -> [typeof x === ...]
718
719
719
720
Note: The function preserves the semantics of the original expression while
720
721
attempting to reduce it to a simpler form. If no simplification is possible,
@@ -828,6 +829,39 @@ let rec simplify_and (e1 : t) (e2 : t) : t option =
828
829
_ ) )
829
830
when Js_op_util. same_vident ia ib ->
830
831
Some false_
832
+ | ( Bin
833
+ ( EqEqEq ,
834
+ {expression_desc = Typeof {expression_desc = Var ia}},
835
+ {expression_desc = Str {txt = " boolean" }} ),
836
+ Bin (NotEqEq , {expression_desc = Var ib}, {expression_desc = Bool _}) )
837
+ | ( Bin (NotEqEq , {expression_desc = Var ib}, {expression_desc = Bool _}),
838
+ Bin
839
+ ( EqEqEq ,
840
+ {expression_desc = Typeof {expression_desc = Var ia}},
841
+ {expression_desc = Str {txt = " boolean" }} ) )
842
+ when Js_op_util. same_vident ia ib ->
843
+ None
844
+ | ( (Bin
845
+ ( EqEqEq ,
846
+ {expression_desc = Typeof {expression_desc = Var ia}},
847
+ {expression_desc = Str {txt = " boolean" | " string" | " number" }} ) as
848
+ typeof),
849
+ Bin
850
+ ( NotEqEq ,
851
+ {expression_desc = Var ib},
852
+ {expression_desc = Bool _ | Null | Undefined _} ) )
853
+ | ( Bin
854
+ ( NotEqEq ,
855
+ {expression_desc = Var ib},
856
+ {expression_desc = Bool _ | Null | Undefined _} ),
857
+ (Bin
858
+ ( EqEqEq ,
859
+ {expression_desc = Typeof {expression_desc = Var ia}},
860
+ {expression_desc = Str {txt = " boolean" | " string" | " number" }} ) as
861
+ typeof) )
862
+ when Js_op_util. same_vident ia ib ->
863
+ (* Note: case boolean / Bool _ is handled above *)
864
+ Some {expression_desc = typeof; comment = None }
831
865
| _ -> None
832
866
833
867
(* *
0 commit comments