Skip to content

Commit 984328c

Browse files
committed
add transformation: if a then {if b then e else d } else e
1 parent 22dca82 commit 984328c

13 files changed

+2050
-3075
lines changed

jscomp/core/js_stmt_make.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,18 @@ let rec if_ ?comment ?declaration ?else_ (e : J.expression) (then_ : J.block)
281281

282282
(*
283283
{[ if a then { if b then d else e} else e ]}
284-
285284
=> if a && b then d else e
286285
*)
287286
| _,
288287
[ {statement_desc = If (pred, then_, Some ([else_] as cont)) }],
289288
[ another_else] when Js_analyzer.eq_statement else_ another_else
290289
->
291290
aux ?comment (E.and_ e pred) then_ cont acc
291+
| _,
292+
[ {statement_desc = If (pred, ([ then_ ] as cont), Some ( else_ )) }],
293+
[ another_else] when Js_analyzer.eq_statement then_ another_else
294+
->
295+
aux ?comment (E.and_ e (E.not pred)) else_ cont acc
292296
| _ ->
293297
let e = E.ocaml_boolean_under_condition e in
294298
{ statement_desc =

jscomp/test/exception_rebound_err_test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ function test_js_error4() {
5151
exit$1 = 2;
5252
}
5353
if (exit$1 === 2) {
54-
if (e[0] === A) {
55-
if (e[1] !== 2) {
56-
exit = 1;
57-
} else {
58-
return 4;
59-
}
54+
if (e[0] === A && e[1] === 2) {
55+
return 4;
6056
} else {
6157
exit = 1;
6258
}

0 commit comments

Comments
 (0)