@@ -997,7 +997,7 @@ let rec simplify_and ~n (e1 : t) (e2 : t) : t option =
997997 _ ) as is_array) )
998998 when Js_op_util. same_vident ia ib ->
999999 Some {expression_desc = is_array; comment = None }
1000- | x , y when x = y -> Some e1
1000+ | _ when Js_analyzer. eq_expression e1 e2 -> Some e1
10011001 | ( Bin
10021002 ( EqEqEq ,
10031003 {expression_desc = Var ia},
@@ -1022,7 +1022,9 @@ let rec simplify_and ~n (e1 : t) (e2 : t) : t option =
10221022 ({expression_desc = Bool _ | Null | Undefined _ | Number _ | Str _}
10231023 as v2) ) )
10241024 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
1025+ if Js_analyzer. eq_expression v1 v2 then Some false_
1026+ else if op1 = EqEqEq then Some e1
1027+ else Some e2
10261028 | _ -> None
10271029 in
10281030 (if debug then
@@ -1138,14 +1140,22 @@ let not (e : t) : t =
11381140 | Bin (Ge, a , b ) -> {e with expression_desc = Bin (Lt , a, b)}
11391141 | Bin (Le, a , b ) -> {e with expression_desc = Bin (Gt , a, b)}
11401142 | Bin (Gt, a , b ) -> {e with expression_desc = Bin (Le , a, b)}
1141- | _ -> {expression_desc = Js_not e; comment = None }
1143+ | _ -> (
1144+ match push_negation e with
1145+ | Some e_ -> e_
1146+ | None -> {expression_desc = Js_not e; comment = None })
11421147
11431148let not_empty_branch (x : t ) =
11441149 match x.expression_desc with
11451150 | Number (Int {i = 0l } ) | Undefined _ -> false
11461151 | _ -> true
11471152
11481153let rec econd ?comment (pred : t ) (ifso : t ) (ifnot : t ) : t =
1154+ let default () =
1155+ if Js_analyzer. eq_expression ifso ifnot then
1156+ if no_side_effect pred then ifso else seq ?comment pred ifso
1157+ else {expression_desc = Cond (pred, ifso, ifnot); comment}
1158+ in
11491159 match (pred.expression_desc, ifso.expression_desc, ifnot.expression_desc) with
11501160 | Bool false , _ , _ -> ifnot
11511161 | Number (Int {i = 0l ; _} ), _ , _ -> ifnot
@@ -1179,10 +1189,15 @@ let rec econd ?comment (pred : t) (ifso : t) (ifnot : t) : t =
11791189 Seq (a, {expression_desc = Undefined _}),
11801190 Seq (b, {expression_desc = Undefined _}) ) ->
11811191 seq (econd ?comment pred a b) undefined
1182- | _ ->
1183- if Js_analyzer. eq_expression ifso ifnot then
1184- if no_side_effect pred then ifso else seq ?comment pred ifso
1185- else {expression_desc = Cond (pred, ifso, ifnot); comment}
1192+ | _ , _ , Bool false -> (
1193+ match simplify_and ~n: 0 pred ifso with
1194+ | Some e -> e
1195+ | None -> default () )
1196+ | _ , Bool false , _ -> (
1197+ match simplify_and ~n: 0 (not pred) ifnot with
1198+ | Some e -> e
1199+ | None -> default () )
1200+ | _ -> default ()
11861201
11871202let rec float_equal ?comment (e0 : t ) (e1 : t ) : t =
11881203 match (e0.expression_desc, e1.expression_desc) with
0 commit comments