Skip to content

Commit 22dca82

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

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2652
-3424
lines changed

jscomp/core/js_stmt_make.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,11 @@ let rec if_ ?comment ?declaration ?else_ (e : J.expression) (then_ : J.block)
284284
285285
=> if a && b then d else e
286286
*)
287-
(* | _,
287+
| _,
288288
[ {statement_desc = If (pred, then_, Some ([else_] as cont)) }],
289289
[ another_else] when Js_analyzer.eq_statement else_ another_else
290290
->
291-
aux ?comment (E.and_ e pred) then_ cont acc *)
291+
aux ?comment (E.and_ e pred) then_ cont acc
292292
| _ ->
293293
let e = E.ocaml_boolean_under_condition e in
294294
{ statement_desc =

jscomp/test/exception_rebound_err_test.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,8 @@ function test_js_error4() {
4545
var exit$1 = 0;
4646
if (e === Caml_builtin_exceptions.not_found) {
4747
return 2;
48-
} else if (e[0] === Caml_builtin_exceptions.invalid_argument) {
49-
if (e[1] === "x") {
50-
return 3;
51-
} else {
52-
exit$1 = 2;
53-
}
48+
} else if (e[0] === Caml_builtin_exceptions.invalid_argument && e[1] === "x") {
49+
return 3;
5450
} else {
5551
exit$1 = 2;
5652
}

jscomp/test/ext_filename_test.js

+5-13
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,11 @@ function relative_path(file_or_dir_1, file_or_dir_2) {
128128
var dir2 = _dir2;
129129
var dir1 = _dir1;
130130
var exit = 0;
131-
if (dir1) {
132-
if (dir2) {
133-
if (dir1[0] === dir2[0]) {
134-
_dir2 = dir2[1];
135-
_dir1 = dir1[1];
136-
continue ;
137-
138-
} else {
139-
exit = 1;
140-
}
141-
} else {
142-
exit = 1;
143-
}
131+
if (dir1 && dir2 && dir1[0] === dir2[0]) {
132+
_dir2 = dir2[1];
133+
_dir1 = dir1[1];
134+
continue ;
135+
144136
} else {
145137
exit = 1;
146138
}

jscomp/test/ext_list_test.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -715,15 +715,11 @@ function for_all2_no_exn(p, _l1, _l2) {
715715
var l2 = _l2;
716716
var l1 = _l1;
717717
if (l1) {
718-
if (l2) {
719-
if (Curry._2(p, l1[0], l2[0])) {
720-
_l2 = l2[1];
721-
_l1 = l1[1];
722-
continue ;
723-
724-
} else {
725-
return /* false */0;
726-
}
718+
if (l2 && Curry._2(p, l1[0], l2[0])) {
719+
_l2 = l2[1];
720+
_l1 = l1[1];
721+
continue ;
722+
727723
} else {
728724
return /* false */0;
729725
}

jscomp/test/ext_pervasives_test.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,10 @@ function dump(r) {
131131
} else {
132132
var s = r.length;
133133
var t = r.tag | 0;
134-
if (t === 0) {
135-
if (s === 2) {
136-
_r = r[1];
137-
continue ;
138-
139-
} else {
140-
return /* false */0;
141-
}
134+
if (t === 0 && s === 2) {
135+
_r = r[1];
136+
continue ;
137+
142138
} else {
143139
return /* false */0;
144140
}

jscomp/test/ext_string_test.js

+23-27
Original file line numberDiff line numberDiff line change
@@ -516,46 +516,42 @@ function is_valid_module_file(s) {
516516

517517
function is_valid_npm_package_name(s) {
518518
var len = s.length;
519-
if (len <= 214) {
520-
if (len > 0) {
521-
var match = s.charCodeAt(0);
522-
var exit = 0;
523-
if (match >= 97) {
524-
if (match >= 123) {
525-
return /* false */0;
526-
} else {
527-
exit = 1;
528-
}
529-
} else if (match !== 64) {
519+
if (len <= 214 && len > 0) {
520+
var match = s.charCodeAt(0);
521+
var exit = 0;
522+
if (match >= 97) {
523+
if (match >= 123) {
530524
return /* false */0;
531525
} else {
532526
exit = 1;
533527
}
534-
if (exit === 1) {
535-
return unsafe_for_all_range(s, 1, len - 1 | 0, (function (x) {
536-
if (x >= 58) {
537-
if (x >= 97) {
538-
if (x >= 123) {
539-
return /* false */0;
540-
} else {
541-
return /* true */1;
542-
}
543-
} else if (x !== 95) {
528+
} else if (match !== 64) {
529+
return /* false */0;
530+
} else {
531+
exit = 1;
532+
}
533+
if (exit === 1) {
534+
return unsafe_for_all_range(s, 1, len - 1 | 0, (function (x) {
535+
if (x >= 58) {
536+
if (x >= 97) {
537+
if (x >= 123) {
544538
return /* false */0;
545539
} else {
546540
return /* true */1;
547541
}
548-
} else if (x !== 45 && x < 48) {
542+
} else if (x !== 95) {
549543
return /* false */0;
550544
} else {
551545
return /* true */1;
552546
}
553-
}));
554-
}
555-
556-
} else {
557-
return /* false */0;
547+
} else if (x !== 45 && x < 48) {
548+
return /* false */0;
549+
} else {
550+
return /* true */1;
551+
}
552+
}));
558553
}
554+
559555
} else {
560556
return /* false */0;
561557
}

0 commit comments

Comments
 (0)