@@ -73506,7 +73506,10 @@ let int_switch ?comment ?declaration ?default (e : J.expression) clauses : t
73506
73506
end in
73507
73507
begin match declaration, continuation with
73508
73508
| Some (kind, did),
73509
- [ {statement_desc = Exp {expression_desc = Bin(Eq, {expression_desc = Var (Id id) ; _}, e0); _}; _}]
73509
+ [ {statement_desc =
73510
+ Exp {
73511
+ expression_desc =
73512
+ Bin(Eq, {expression_desc = Var (Id id) ; _}, e0); _}; _}]
73510
73513
when Ident.same did id
73511
73514
->
73512
73515
define_variable ?comment ~kind id e0
@@ -73515,13 +73518,13 @@ let int_switch ?comment ?declaration ?default (e : J.expression) clauses : t
73515
73518
block (declare_variable ?comment ~kind did :: continuation)
73516
73519
| None, _ -> block continuation
73517
73520
end
73518
-
73519
73521
| _ ->
73520
- match declaration with
73522
+ begin match declaration with
73521
73523
| Some (kind, did) ->
73522
73524
block [declare_variable ?comment ~kind did ;
73523
73525
{ statement_desc = J.Int_switch (e,clauses, default); comment}]
73524
73526
| None -> { statement_desc = J.Int_switch (e,clauses, default); comment}
73527
+ end
73525
73528
73526
73529
let string_switch ?comment ?declaration ?default (e : J.expression) clauses : t=
73527
73530
match e.expression_desc with
@@ -73581,15 +73584,21 @@ let rec if_ ?comment ?declaration ?else_ (e : J.expression) (then_ : J.block)
73581
73584
let declared = ref false in
73582
73585
let rec aux ?comment (e : J.expression) (then_ : J.block) (else_ : J.block ) acc =
73583
73586
match e.expression_desc, then_, (else_ : J.block ) with
73584
- | _, [ {statement_desc = Return {return_value = b; _}; _}],
73587
+ | _,
73588
+ [ {statement_desc = Return {return_value = b; _}; _}],
73585
73589
[ {statement_desc = Return {return_value = a; _}; _}]
73586
73590
->
73587
73591
return_stmt (E.econd e b a ) :: acc
73588
- | _, [ {statement_desc =
73589
- Exp {expression_desc = Bin(Eq, ({expression_desc = Var (Id id0); _} as l0), a0); _}; _}],
73592
+ | _,
73590
73593
[ {statement_desc =
73591
- Exp ({ expression_desc = Bin(Eq,
73592
- {expression_desc = Var (Id id1); _}, b0); _}); _}]
73594
+ Exp
73595
+ {expression_desc = Bin(Eq, ({expression_desc = Var (Id id0); _} as l0), a0); _};
73596
+ _}],
73597
+ [ {statement_desc =
73598
+ Exp (
73599
+ { expression_desc =
73600
+ Bin(Eq,
73601
+ {expression_desc = Var (Id id1); _}, b0); _}); _}]
73593
73602
when Ident.same id0 id1 ->
73594
73603
begin match declaration with
73595
73604
| Some (kind,did) when Ident.same did id0 ->
@@ -73602,13 +73611,13 @@ let rec if_ ?comment ?declaration ?else_ (e : J.expression) (then_ : J.block)
73602
73611
exp (E.assign l0 (E.econd e a0 b0)) :: acc
73603
73612
end
73604
73613
73605
- | _, _,
73606
- [ {statement_desc = Exp {expression_desc = Number _}; _}]
73614
+ | _, _,
73615
+ ( {statement_desc = Exp {expression_desc = Number _}; _}::more_else)
73607
73616
->
73608
- aux ?comment e then_ [] acc
73609
- | _, [ {statement_desc = Exp {expression_desc = Number _}; _}] , _
73617
+ aux ?comment e then_ more_else acc
73618
+ | _, ( {statement_desc = Exp {expression_desc = Number _}; _} :: more_then) , _
73610
73619
->
73611
- aux ?comment e [] else_ acc
73620
+ aux ?comment e more_then else_ acc
73612
73621
73613
73622
| _, [ {statement_desc = Exp b; _}], [ {statement_desc = Exp a; _}]
73614
73623
->
@@ -73629,6 +73638,7 @@ let rec if_ ?comment ?declaration ?else_ (e : J.expression) (then_ : J.block)
73629
73638
move code outside of branch is generally helpful later
73630
73639
*)
73631
73640
aux ?comment e ys xs (y::acc)
73641
+
73632
73642
73633
73643
| Number ( Int { i = 0l; _}) , _, _
73634
73644
->
@@ -73664,13 +73674,24 @@ let rec if_ ?comment ?declaration ?else_ (e : J.expression) (then_ : J.block)
73664
73674
(** Add comment when simplified *)
73665
73675
aux ?comment e then_ else_ acc
73666
73676
73677
+ (*
73678
+ {[ if a then { if b then d else e} else e ]}
73679
+
73680
+ => if a && b then d else e
73681
+ *)
73682
+ (* | _,
73683
+ [ {statement_desc = If (pred, then_, Some ([else_] as cont)) }],
73684
+ [ another_else] when Js_analyzer.eq_statement else_ another_else
73685
+ ->
73686
+ aux ?comment (E.and_ e pred) then_ cont acc *)
73667
73687
| _ ->
73668
73688
let e = E.ocaml_boolean_under_condition e in
73669
- { statement_desc = If (e,
73670
- then_,
73671
- (match else_ with
73672
- | [] -> None
73673
- | v -> Some v));
73689
+ { statement_desc =
73690
+ If (e,
73691
+ then_,
73692
+ (match else_ with
73693
+ | [] -> None
73694
+ | v -> Some v));
73674
73695
comment } :: acc in
73675
73696
let if_block =
73676
73697
aux ?comment e then_ (match else_ with None -> [] | Some v -> v) [] in
0 commit comments