Skip to content

Commit 2e3ec46

Browse files
committed
add transformat: if a then {e } else {if b then {e} else d}
1 parent 984328c commit 2e3ec46

30 files changed

+182
-396
lines changed

jscomp/core/js_stmt_make.ml

+6
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ let rec if_ ?comment ?declaration ?else_ (e : J.expression) (then_ : J.block)
293293
[ another_else] when Js_analyzer.eq_statement then_ another_else
294294
->
295295
aux ?comment (E.and_ e (E.not pred)) else_ cont acc
296+
| _,
297+
([ another_then] as cont),
298+
[ {statement_desc = If (pred, [then_], Some (else_ )) }]
299+
when Js_analyzer.eq_statement then_ another_then
300+
->
301+
aux ?comment (E.or_ e pred) cont else_ acc
296302
| _ ->
297303
let e = E.ocaml_boolean_under_condition e in
298304
{ statement_desc =

jscomp/test/exception_raise_test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ try {
101101
}
102102
catch (raw_exn$3){
103103
var exn$3 = Js_exn.internalToOCamlException(raw_exn$3);
104-
if (exn$3[0] === A) {
105-
a0 = exn$3[1];
106-
} else if (exn$3[0] === Js_exn.$$Error) {
104+
if (exn$3[0] === A || exn$3[0] === Js_exn.$$Error) {
107105
a0 = exn$3[1];
108106
} else {
109107
throw [

jscomp/test/ext_array_test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ function rfind_with_index(arr, cmp, v) {
202202
var _i = len - 1 | 0;
203203
while(true) {
204204
var i = _i;
205-
if (i < 0) {
206-
return i;
207-
} else if (Curry._2(cmp, arr[i], v)) {
205+
if (i < 0 || Curry._2(cmp, arr[i], v)) {
208206
return i;
209207
} else {
210208
_i = i - 1 | 0;

jscomp/test/ext_string_test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,7 @@ function unsafe_concat_with_length(len, sep, l) {
429429
function rindex_rec(s, _i, c) {
430430
while(true) {
431431
var i = _i;
432-
if (i < 0) {
433-
return i;
434-
} else if (s.charCodeAt(i) === c) {
432+
if (i < 0 || s.charCodeAt(i) === c) {
435433
return i;
436434
} else {
437435
_i = i - 1 | 0;

jscomp/test/flow_parser_reg_test.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -9255,9 +9255,7 @@ function property$1(env) {
92559255
var match$1 = key(env);
92569256
var tmp;
92579257
var exit = 0;
9258-
if (async$1 !== 0) {
9259-
exit = 1;
9260-
} else if (match !== 0) {
9258+
if (async$1 !== 0 || match !== 0) {
92619259
exit = 1;
92629260
} else {
92639261
var key$1 = match$1[1];
@@ -9802,9 +9800,7 @@ function class_element(env) {
98029800
var generator$1 = generator(env, async$1);
98039801
var match = key(env);
98049802
var exit = 0;
9805-
if (async$1 !== 0) {
9806-
exit = 1;
9807-
} else if (generator$1 !== 0) {
9803+
if (async$1 !== 0 || generator$1 !== 0) {
98089804
exit = 1;
98099805
} else {
98109806
var key$1 = match[1];
@@ -11042,7 +11038,7 @@ function assert_can_be_forin_or_forof(env, err, param) {
1104211038
var match$2 = match[0];
1104311039
var declarations = match$2[1][/* declarations */0];
1104411040
var exit = 0;
11045-
if (declarations && !declarations[0][1][/* init */1] && !declarations[1]) {
11041+
if (declarations && !(declarations[0][1][/* init */1] || declarations[1])) {
1104611042
return /* () */0;
1104711043
} else {
1104811044
exit = 1;

jscomp/test/inline_map2_test.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,7 @@ function Make(Ord) {
328328
while(true) {
329329
var param = _param;
330330
if (param) {
331-
if (Curry._2(p, param[1], param[2])) {
332-
return /* true */1;
333-
} else if (exists(p, param[0])) {
331+
if (Curry._2(p, param[1], param[2]) || exists(p, param[0])) {
334332
return /* true */1;
335333
} else {
336334
_param = param[3];
@@ -997,9 +995,7 @@ function exists(p, _param) {
997995
while(true) {
998996
var param = _param;
999997
if (param) {
1000-
if (Curry._2(p, param[1], param[2])) {
1001-
return /* true */1;
1002-
} else if (exists(p, param[0])) {
998+
if (Curry._2(p, param[1], param[2]) || exists(p, param[0])) {
1003999
return /* true */1;
10041000
} else {
10051001
_param = param[3];
@@ -1714,9 +1710,7 @@ function exists$1(p, _param) {
17141710
while(true) {
17151711
var param = _param;
17161712
if (param) {
1717-
if (Curry._2(p, param[1], param[2])) {
1718-
return /* true */1;
1719-
} else if (exists$1(p, param[0])) {
1713+
if (Curry._2(p, param[1], param[2]) || exists$1(p, param[0])) {
17201714
return /* true */1;
17211715
} else {
17221716
_param = param[3];

jscomp/test/int_map.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,7 @@ function exists(p, _param) {
341341
while(true) {
342342
var param = _param;
343343
if (param) {
344-
if (Curry._2(p, param[1], param[2])) {
345-
return /* true */1;
346-
} else if (exists(p, param[0])) {
344+
if (Curry._2(p, param[1], param[2]) || exists(p, param[0])) {
347345
return /* true */1;
348346
} else {
349347
_param = param[3];

jscomp/test/miss_colon_test.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,14 @@ function $star$colon(_f, _g) {
7272
}
7373
}
7474
if (exit$2 === 3) {
75-
if (g.tag) {
76-
exit$1 = 2;
77-
} else if (g[0] !== 0) {
75+
if (g.tag || g[0] !== 0) {
7876
exit$1 = 2;
7977
} else {
8078
return /* Int */Block.__(0, [0]);
8179
}
8280
}
8381
if (exit$1 === 2) {
84-
if (f.tag) {
85-
exit = 1;
86-
} else if (f[0] !== 1) {
82+
if (f.tag || f[0] !== 1) {
8783
exit = 1;
8884
} else {
8985
return g;

jscomp/test/ocaml_parsetree_test.js

+42-52
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)