Skip to content

Commit 09116cb

Browse files
committed
Some simplification.
1 parent a62067d commit 09116cb

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

jscomp/core/js_exp_make.ml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,23 @@ let bin ?comment (op : J.binop) (e0 : t) (e1 : t) : t =
618618
be careful for side effect
619619
*)
620620

621+
let rec filter_bool (e: t) ~j ~b = match e.expression_desc with
622+
| Bin (And, e1, e2) ->
623+
(match (filter_bool e1 ~j ~b, filter_bool e2 ~j ~b) with
624+
| None, None -> None
625+
| Some e, None
626+
| None, Some e -> Some e
627+
| Some e1, Some e2 ->
628+
Some {e with expression_desc = Bin (And, e1, e2)} )
629+
| Bin
630+
( NotEqEq,
631+
{expression_desc = Typeof {expression_desc = Var i}},
632+
{expression_desc = Str {txt}}) when Js_op_util.same_vident i j ->
633+
if txt <> "bool"
634+
then None
635+
else assert false
636+
| _ -> Some e
637+
621638
let and_ ?comment (e1 : t) (e2 : t) : t =
622639
match (e1.expression_desc, e2.expression_desc) with
623640
| Var i, Var j when Js_op_util.same_vident i j -> e1
@@ -634,6 +651,15 @@ let and_ ?comment (e1 : t) (e2 : t) : t =
634651
{ expression_desc = Str _ | Number _ } ) )
635652
when Js_op_util.same_vident i j ->
636653
e2
654+
| ( _,
655+
Bin
656+
( EqEqEq,
657+
{ expression_desc = Var j },
658+
{ expression_desc = Bool b } )
659+
) ->
660+
(match filter_bool e1 ~j ~b with
661+
| None -> e2
662+
| Some e1 -> { expression_desc = Bin (And, e1, e2); comment })
637663
| _, _ -> { expression_desc = Bin (And, e1, e2); comment }
638664

639665
let or_ ?comment (e1 : t) (e2 : t) =

jscomp/test/UntaggedVariants.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)