@@ -663,20 +663,26 @@ let bin ?comment (op : J.binop) (e0 : t) (e1 : t) : t =
663
663
*)
664
664
665
665
type filter_const = Ctrue | Cnull
666
-
667
- let rec filter_const (e : t ) ~j ~b :eq ~const =
666
+ let string_of_filter_const = function
667
+ | Ctrue -> " Ctrue"
668
+ | Cnull -> " Cnull"
669
+
670
+ let string_of_expression = ref (fun _ -> " " )
671
+ let debug = false
672
+
673
+ let rec filter_const (e : t ) ~j ~eq ~const =
674
+ if debug then
675
+ Printf. eprintf " filter_const e:%s eq:%b const:%s\n "
676
+ (! string_of_expression e) eq
677
+ (string_of_filter_const const);
668
678
match e.expression_desc with
669
679
| Bin (And, e1 , e2 ) -> (
670
- match
671
- (filter_const e1 ~j ~b: eq ~const , filter_const e2 ~j ~b: eq ~const )
672
- with
680
+ match (filter_const e1 ~j ~eq ~const , filter_const e2 ~j ~eq ~const ) with
673
681
| None , None -> None
674
682
| Some e , None | None , Some e -> Some e
675
683
| Some e1 , Some e2 -> Some {e with expression_desc = Bin (And , e1, e2)})
676
684
| Bin (Or, e1 , e2 ) -> (
677
- match
678
- (filter_const e1 ~j ~b: eq ~const , filter_const e2 ~j ~b: eq ~const )
679
- with
685
+ match (filter_const e1 ~j ~eq ~const , filter_const e2 ~j ~eq ~const ) with
680
686
| None , _ | _ , None -> None
681
687
| Some e1 , Some e2 -> Some {e with expression_desc = Bin (Or , e1, e2)})
682
688
| Bin (EqEqEq , {expression_desc = Var i}, {expression_desc = Bool b1})
@@ -690,14 +696,8 @@ let rec filter_const (e : t) ~j ~b:eq ~const =
690
696
| Bin
691
697
( NotEqEq ,
692
698
{expression_desc = Typeof {expression_desc = Var i}},
693
- {expression_desc = Str {txt = " bool" }} )
694
- when Js_op_util. same_vident i j && const = Ctrue ->
695
- None
696
- | Bin
697
- ( NotEqEq ,
698
- {expression_desc = Typeof {expression_desc = Var i}},
699
- {expression_desc = Str {txt = " string" }} )
700
- when Js_op_util. same_vident i j && (const = Cnull || const = Ctrue ) ->
699
+ {expression_desc = Str {txt = " boolean" | " string" }} )
700
+ when Js_op_util. same_vident i j && (const = Ctrue || const = Cnull ) ->
701
701
None
702
702
| Js_not
703
703
{
@@ -737,7 +737,7 @@ let and_ ?comment (e1 : t) (e2 : t) : t =
737
737
{expression_desc = Bool b} ),
738
738
_ ) -> (
739
739
match
740
- filter_const e1 ~j ~b : (if op = EqEqEq then b else not b) ~const: Ctrue
740
+ filter_const e1 ~j ~eq : (if op = EqEqEq then b else not b) ~const: Ctrue
741
741
with
742
742
| None -> e2
743
743
| Some e1 -> {expression_desc = Bin (And , e1, e2); comment})
@@ -751,7 +751,7 @@ let and_ ?comment (e1 : t) (e2 : t) : t =
751
751
{expression_desc = Var j},
752
752
{expression_desc = Null } ),
753
753
_ ) -> (
754
- match filter_const e1 ~j ~b : (op = EqEqEq ) ~const: Cnull with
754
+ match filter_const e1 ~j ~eq : (op = EqEqEq ) ~const: Cnull with
755
755
| None -> e2
756
756
| Some e1 -> {expression_desc = Bin (And , e1, e2); comment})
757
757
| _ , _ -> {expression_desc = Bin (And , e1, e2); comment}
@@ -770,15 +770,15 @@ let or_ ?comment (e1 : t) (e2 : t) =
770
770
( ((EqEqEq | NotEqEq ) as op),
771
771
{expression_desc = Var j},
772
772
{expression_desc = Null } ) ) -> (
773
- match filter_const e1 ~j ~b : (op <> EqEqEq ) ~const: Cnull with
773
+ match filter_const e1 ~j ~eq : (op <> EqEqEq ) ~const: Cnull with
774
774
| None -> e2
775
775
| Some e1 -> {expression_desc = Bin (Or , e1, e2); comment})
776
776
| ( Bin
777
777
( ((EqEqEq | NotEqEq ) as op),
778
778
{expression_desc = Var j},
779
779
{expression_desc = Null } ),
780
780
_ ) -> (
781
- match filter_const e2 ~j ~b : (op <> EqEqEq ) ~const: Cnull with
781
+ match filter_const e2 ~j ~eq : (op <> EqEqEq ) ~const: Cnull with
782
782
| None -> e1
783
783
| Some e2 -> {expression_desc = Bin (Or , e1, e2); comment})
784
784
| _ , _ -> {expression_desc = Bin (Or , e1, e2); comment}
0 commit comments