Skip to content

Commit e5d7218

Browse files
committed
last round if transformat
1 parent 2e3ec46 commit e5d7218

13 files changed

+489
-850
lines changed

jscomp/core/js_stmt_make.ml

+8
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,14 @@ let rec if_ ?comment ?declaration ?else_ (e : J.expression) (then_ : J.block)
299299
when Js_analyzer.eq_statement then_ another_then
300300
->
301301
aux ?comment (E.or_ e pred) cont else_ acc
302+
303+
| _,
304+
([ another_then] as cont),
305+
[ {statement_desc = If (pred, then_, Some [else_] ) }]
306+
when Js_analyzer.eq_statement else_ another_then
307+
->
308+
aux ?comment (E.or_ e (E.not pred)) cont then_ acc
309+
302310
| _ ->
303311
let e = E.ocaml_boolean_under_condition e in
304312
{ statement_desc =

jscomp/test/and_or_tailcall_test.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ var Block = require("../../lib/js/block.js");
66
function f(b, _, _n) {
77
while(true) {
88
var n = _n;
9-
if (n > 100000) {
9+
if (n > 100000 || !b) {
1010
return /* false */0;
11-
} else if (b) {
11+
} else {
1212
_n = n + 1 | 0;
1313
continue ;
1414

15-
} else {
16-
return /* false */0;
1715
}
1816
};
1917
}

jscomp/test/flow_parser_reg_test.js

+23-43
Original file line numberDiff line numberDiff line change
@@ -8233,12 +8233,10 @@ function try_assignment_but_not_arrow_function(env) {
82338233
throw Parser_env_051[/* Rollback */0];
82348234
} else {
82358235
var match$1 = ret[1];
8236-
if (typeof match$1 === "number") {
8236+
if (typeof match$1 === "number" || !(match$1.tag === 18 && match$1[0][1][/* name */0] === "async" && !Curry._1(Parser_env_048[/* is_line_terminator */5], env$1))) {
82378237
return ret;
8238-
} else if (match$1.tag === 18 && match$1[0][1][/* name */0] === "async" && !Curry._1(Parser_env_048[/* is_line_terminator */5], env$1)) {
8239-
throw Parser_env_051[/* Rollback */0];
82408238
} else {
8241-
return ret;
8239+
throw Parser_env_051[/* Rollback */0];
82428240
}
82438241
}
82448242
} else {
@@ -8261,9 +8259,9 @@ function assignment(env) {
82618259
} else {
82628260
exit = 1;
82638261
}
8264-
} else if (switcher !== 52) {
8262+
} else if (switcher !== 52 || !env[/* allow_yield */13]) {
82658263
exit$1 = 2;
8266-
} else if (env[/* allow_yield */13]) {
8264+
} else {
82678265
var env$1 = env;
82688266
var start_loc = Curry._2(Parser_env_048[/* loc */2], /* None */0, env$1);
82698267
token$4(env$1, /* T_YIELD */56);
@@ -8289,8 +8287,6 @@ function assignment(env) {
82898287
/* delegate */delegate
82908288
]])
82918289
];
8292-
} else {
8293-
exit$1 = 2;
82948290
}
82958291
} else {
82968292
exit$1 = 2;
@@ -10221,9 +10217,9 @@ function declare($staropt$star, env) {
1022110217
return declare_var_statement(env, start_loc);
1022210218
}
1022310219
} else if (match !== 13) {
10224-
if (match !== 0) {
10220+
if (match !== 0 || Curry._2(Parser_env_048[/* value */1], /* Some */[1], env) !== "module") {
1022510221
exit = 1;
10226-
} else if (Curry._2(Parser_env_048[/* value */1], /* Some */[1], env) === "module") {
10222+
} else {
1022710223
token$4(env, /* T_DECLARE */58);
1022810224
contextual(env, "module");
1022910225
if (in_module || Curry._2(Parser_env_048[/* token */0], /* None */0, env) === /* T_PERIOD */9) {
@@ -10296,8 +10292,6 @@ function declare($staropt$star, env) {
1029610292
]])
1029710293
];
1029810294
}
10299-
} else {
10300-
exit = 1;
1030110295
}
1030210296
} else {
1030310297
token$4(env, /* T_DECLARE */58);
@@ -10408,9 +10402,9 @@ function export_source(env) {
1040810402
contextual(env, "from");
1040910403
var match = Curry._2(Parser_env_048[/* token */0], /* None */0, env);
1041010404
var exit = 0;
10411-
if (typeof match === "number") {
10405+
if (typeof match === "number" || match.tag !== 1) {
1041210406
exit = 1;
10413-
} else if (match.tag === 1) {
10407+
} else {
1041410408
var match$1 = match[0];
1041510409
var octal = match$1[3];
1041610410
var raw = match$1[2];
@@ -10433,8 +10427,6 @@ function export_source(env) {
1043310427
/* raw */raw
1043410428
]
1043510429
];
10436-
} else {
10437-
exit = 1;
1043810430
}
1043910431
if (exit === 1) {
1044010432
var raw$1 = Curry._2(Parser_env_048[/* value */1], /* None */0, env);
@@ -10896,12 +10888,10 @@ function module_items(env, _module_kind, _acc) {
1089610888
var module_kind$1;
1089710889
if (module_kind) {
1089810890
if (module_kind[0].tag) {
10899-
if (typeof stmt$1 === "number") {
10900-
module_kind$1 = module_kind;
10901-
} else if (stmt$1.tag === 26) {
10902-
error$1(env, /* AmbiguousDeclareModuleKind */61);
10891+
if (typeof stmt$1 === "number" || stmt$1.tag !== 26) {
1090310892
module_kind$1 = module_kind;
1090410893
} else {
10894+
error$1(env, /* AmbiguousDeclareModuleKind */61);
1090510895
module_kind$1 = module_kind;
1090610896
}
1090710897
} else if (typeof stmt$1 === "number") {
@@ -11172,9 +11162,9 @@ function source(env) {
1117211162
contextual(env, "from");
1117311163
var match = Curry._2(Parser_env_048[/* token */0], /* None */0, env);
1117411164
var exit = 0;
11175-
if (typeof match === "number") {
11165+
if (typeof match === "number" || match.tag !== 1) {
1117611166
exit = 1;
11177-
} else if (match.tag === 1) {
11167+
} else {
1117811168
var match$1 = match[0];
1117911169
var octal = match$1[3];
1118011170
var raw = match$1[2];
@@ -11197,8 +11187,6 @@ function source(env) {
1119711187
/* raw */raw
1119811188
]
1119911189
];
11200-
} else {
11201-
exit = 1;
1120211190
}
1120311191
if (exit === 1) {
1120411192
var raw$1 = Curry._2(Parser_env_048[/* value */1], /* None */0, env);
@@ -13164,9 +13152,9 @@ function statement(env) {
1316413152
var match$21 = expr$1[1];
1316513153
var loc$5 = expr$1[0];
1316613154
var exit$4 = 0;
13167-
if (typeof match$21 === "number") {
13155+
if (typeof match$21 === "number" || !(match$21.tag === 18 && typeof match$20 === "number" && match$20 === 77)) {
1316813156
exit$4 = 1;
13169-
} else if (match$21.tag === 18 && typeof match$20 === "number" && match$20 === 77) {
13157+
} else {
1317013158
var label$4 = match$21[0];
1317113159
var match$22 = label$4[1];
1317213160
var name$2 = match$22[/* name */0];
@@ -13189,8 +13177,6 @@ function statement(env) {
1318913177
/* body */labeled_stmt
1319013178
]])
1319113179
];
13192-
} else {
13193-
exit$4 = 1;
1319413180
}
1319513181
if (exit$4 === 1) {
1319613182
var match$23 = Curry._2(Parser_env_048[/* semicolon_loc */7], /* None */0, env$14);
@@ -13515,19 +13501,15 @@ function directives(env, term_fn, item_fn) {
1351513501
var param$1 = param;
1351613502
var token = param$1[1];
1351713503
var exit = 0;
13518-
if (typeof token === "number") {
13504+
if (typeof token === "number" || token.tag !== 1) {
1351913505
exit = 1;
13520-
} else if (token.tag === 1) {
13521-
if (token[0][3]) {
13522-
return strict_error_at(env$2, /* tuple */[
13523-
param$1[0],
13524-
/* StrictOctalLiteral */31
13525-
]);
13526-
} else {
13527-
return 0;
13528-
}
13506+
} else if (token[0][3]) {
13507+
return strict_error_at(env$2, /* tuple */[
13508+
param$1[0],
13509+
/* StrictOctalLiteral */31
13510+
]);
1352913511
} else {
13530-
exit = 1;
13512+
return 0;
1353113513
}
1353213514
if (exit === 1) {
1353313515
var s = "Nooo: " + (token_to_string(token) + "\n");
@@ -14955,9 +14937,9 @@ function parse(content, _) {
1495514937
}
1495614938
var props;
1495714939
var exit = 0;
14958-
if (typeof value === "number") {
14940+
if (typeof value === "number" || value.tag !== 3) {
1495914941
exit = 1;
14960-
} else if (value.tag === 3) {
14942+
} else {
1496114943
var match$1 = value[0];
1496214944
var regex = Curry._1(obj, /* array */[
1496314945
/* tuple */[
@@ -14983,8 +14965,6 @@ function parse(content, _) {
1498314965
regex
1498414966
]
1498514967
];
14986-
} else {
14987-
exit = 1;
1498814968
}
1498914969
if (exit === 1) {
1499014970
props = /* array */[

jscomp/test/ocaml_parsetree_test.js

+7-13
Original file line numberDiff line numberDiff line change
@@ -9603,15 +9603,15 @@ function directive_parse(token_with_comments, lexbuf) {
96039603
case "=~" :
96049604
if (calc) {
96059605
var exit$1 = 0;
9606-
if (typeof lhs === "number") {
9606+
if (typeof lhs === "number" || lhs.tag !== 3) {
96079607
exit$1 = 2;
9608-
} else if (lhs.tag === 3) {
9608+
} else {
96099609
var curr_loc = curr(lexbuf);
96109610
var rhs = value_of_token(curr_loc, token(/* () */0));
96119611
var exit$2 = 0;
9612-
if (typeof rhs === "number") {
9612+
if (typeof rhs === "number" || rhs.tag !== 3) {
96139613
exit$2 = 3;
9614-
} else if (rhs.tag === 3) {
9614+
} else {
96159615
var loc = curr_loc;
96169616
var lhs$1 = lhs[0];
96179617
var str = rhs[0];
@@ -9722,8 +9722,6 @@ function directive_parse(token_with_comments, lexbuf) {
97229722
return Caml_obj.caml_greaterequal(lversion, version);
97239723
}
97249724
}
9725-
} else {
9726-
exit$2 = 3;
97279725
}
97289726
if (exit$2 === 3) {
97299727
throw [
@@ -9736,8 +9734,6 @@ function directive_parse(token_with_comments, lexbuf) {
97369734
];
97379735
}
97389736

9739-
} else {
9740-
exit$1 = 2;
97419737
}
97429738
if (exit$1 === 2) {
97439739
throw [
@@ -11885,13 +11881,11 @@ function wrap(parsing_fun, lexbuf) {
1188511881
var exit$2 = 0;
1188611882
if (err[0] === $$Error$2) {
1188711883
var tmp = err[1];
11888-
if (typeof tmp === "number" || tmp.tag) {
11884+
if (typeof tmp === "number" || tmp.tag || input_name[0] !== "//toplevel//") {
1188911885
exit$2 = 3;
11890-
} else if (input_name[0] === "//toplevel//") {
11886+
} else {
1189111887
skip_phrase(lexbuf);
1189211888
throw err;
11893-
} else {
11894-
exit$2 = 3;
1189511889
}
1189611890
} else {
1189711891
exit$2 = 3;
@@ -12133,7 +12127,7 @@ if (match) {
1213312127
var match$95 = match$94[/* loc_start */0];
1213412128
if (match$95[/* pos_fname */0] === "" && !(match$95[/* pos_lnum */1] !== 1 || match$95[/* pos_bol */2] !== 0 || match$95[/* pos_cnum */3] !== 6)) {
1213512129
var match$96 = match$94[/* loc_end */1];
12136-
if (match$96[/* pos_fname */0] === "" && !(match$96[/* pos_lnum */1] !== 4 || match$96[/* pos_bol */2] !== 46 || match$96[/* pos_cnum */3] !== 71) && match$94[/* loc_ghost */2] !== 0 && !(match$13[/* pexp_attributes */2] || match$3[/* pvb_attributes */2])) {
12130+
if (match$96[/* pos_fname */0] === "" && !(match$96[/* pos_lnum */1] !== 4 || match$96[/* pos_bol */2] !== 46 || match$96[/* pos_cnum */3] !== 71 || !(match$94[/* loc_ghost */2] !== 0 && !(match$13[/* pexp_attributes */2] || match$3[/* pvb_attributes */2])))) {
1213712131
var match$97 = match$3[/* pvb_loc */3];
1213812132
var match$98 = match$97[/* loc_start */0];
1213912133
if (match$98[/* pos_fname */0] === "" && !(match$98[/* pos_lnum */1] !== 1 || match$98[/* pos_bol */2] !== 0 || match$98[/* pos_cnum */3] !== 0)) {

jscomp/test/ocaml_proto_test.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -2989,12 +2989,10 @@ function endline(s) {
29892989

29902990
function gen_pp_field(field_type) {
29912991
var exit = 0;
2992-
if (typeof field_type === "number") {
2992+
if (typeof field_type === "number" || !field_type.tag) {
29932993
exit = 1;
2994-
} else if (field_type.tag) {
2995-
return function_name_of_user_defined("pp", field_type[0]);
29962994
} else {
2997-
exit = 1;
2995+
return function_name_of_user_defined("pp", field_type[0]);
29982996
}
29992997
if (exit === 1) {
30002998
return Curry._1(Printf.sprintf(/* Format */[

0 commit comments

Comments
 (0)