Skip to content

Commit fcfa9e4

Browse files
committed
Tweak codegen to merge if branches
1 parent 7c4225c commit fcfa9e4

13 files changed

+1959
-2268
lines changed

jscomp/core/js_stmt_make.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,18 +213,16 @@ let rec if_ ?comment ?declaration ?else_ (e : J.expression) (then_ : J.block)
213213
let common_prefix_blocks = ref [] in
214214
let add_prefix b = common_prefix_blocks := b :: !common_prefix_blocks in
215215
let rec aux ?comment (e : J.expression) (ifso : J.block) (ifnot : J.block ): t =
216-
match e.expression_desc with
217-
| Bool boolean ->
216+
match e.expression_desc,ifnot with
217+
| Bool boolean, _ ->
218218
block (if boolean then ifso else ifnot)
219-
| Js_not pred_not
219+
| Js_not pred_not, (_::_)
220220
-> aux ?comment pred_not ifnot ifso
221221
| _ ->
222222
match ifso, ifnot with
223223
| [], [] -> exp e
224224
| [], _ ->
225-
{
226-
statement_desc = If ( E.not e, ifnot, []); comment
227-
}
225+
aux ?comment (E.not e) ifnot [] (*Make sure no infinite loop*)
228226
| [ {statement_desc = Return {return_value = ret_ifso; _}; _}],
229227
[ {statement_desc = Return {return_value = ret_ifnot; _}; _} as _ifnot_stmt]
230228
->

jscomp/test/flow_parser_reg_test.js

Lines changed: 244 additions & 277 deletions
Large diffs are not rendered by default.

jscomp/test/ocaml_parsetree_test.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10140,11 +10140,8 @@ function directive_parse(token_with_comments, lexbuf) {
1014010140
var value_v = query(curr_loc, curr_token[0]);
1014110141
return token_op(calc, (function (e) {
1014210142
push(e);
10143-
if (typeof value_v !== "number") {
10144-
if (!value_v.tag) {
10145-
return value_v[0];
10146-
}
10147-
10143+
if (typeof value_v !== "number" && !value_v.tag) {
10144+
return value_v[0];
1014810145
}
1014910146
var ty = type_of_directive(value_v);
1015010147
throw [

jscomp/test/ocaml_proto_test.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,11 +2941,8 @@ function endline(s) {
29412941
}
29422942

29432943
function gen_pp_field(field_type) {
2944-
if (typeof field_type !== "number") {
2945-
if (field_type.tag) {
2946-
return function_name_of_user_defined("pp", field_type[0]);
2947-
}
2948-
2944+
if (typeof field_type !== "number" && field_type.tag) {
2945+
return function_name_of_user_defined("pp", field_type[0]);
29492946
}
29502947
return Curry._1(Printf.sprintf(/* Format */[
29512948
/* String_literal */Block.__(11, [

jscomp/test/ocaml_typedtree_test.js

Lines changed: 1053 additions & 1221 deletions
Large diffs are not rendered by default.

jscomp/test/parser_api.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4453,11 +4453,8 @@ function extension(loc, attrs, a) {
44534453

44544454
function force_poly(t) {
44554455
var match = t[/* ptyp_desc */0];
4456-
if (typeof match !== "number") {
4457-
if (match.tag === 8) {
4458-
return t;
4459-
}
4460-
4456+
if (typeof match !== "number" && match.tag === 8) {
4457+
return t;
44614458
}
44624459
return poly(t[/* ptyp_loc */1], undefined, /* [] */0, t);
44634460
}
@@ -12881,11 +12878,8 @@ function directive_parse(token_with_comments, lexbuf) {
1288112878
var value_v = query(curr_loc, curr_token[0]);
1288212879
return token_op(calc, (function (e) {
1288312880
push(e);
12884-
if (typeof value_v !== "number") {
12885-
if (!value_v.tag) {
12886-
return value_v[0];
12887-
}
12888-
12881+
if (typeof value_v !== "number" && !value_v.tag) {
12882+
return value_v[0];
1288912883
}
1289012884
var ty = type_of_directive(value_v);
1289112885
throw [

0 commit comments

Comments
 (0)