Skip to content

Commit 71f0f21

Browse files
authored
Merge pull request #4390 from BuckleScript/tweak_lazy_encoding
paren-less for `bs.as json literal`
2 parents 1bd5ba4 + c7dbf6c commit 71f0f21

36 files changed

+242
-94
lines changed

jscomp/core/js_dump.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,9 @@ and expression_desc cxt ~(level:int) f x : cxt =
680680
(match info with
681681
| Exp exp_info ->
682682
let raw_paren =
683-
not (match exp_info with Js_literal _ -> true | _ -> false || raw_snippet_exp_simple_enough s) in
683+
not (match exp_info with
684+
| Js_literal _ | Js_raw_json -> true
685+
| Js_function _ | Js_exp_unknown -> false || raw_snippet_exp_simple_enough s) in
684686
if raw_paren then P.string f L.lparen;
685687
P.string f s ;
686688
if raw_paren then P.string f L.rparen;

jscomp/core/js_exp_make.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,8 @@ let rec econd ?comment (pred : t) (ifso : t) (ifnot : t) : t =
775775
| Js_not e, _, _ when not_empty_branch ifnot
776776
->
777777
econd ?comment e ifnot ifso
778+
| _, Seq (a,{expression_desc = Undefined}), Seq(b,{expression_desc = Undefined})
779+
-> seq (econd ?comment pred a b ) undefined
778780
| _ ->
779781
if Js_analyzer.eq_expression ifso ifnot then
780782
if no_side_effect pred then ifso else seq ?comment pred ifso

jscomp/core/js_raw_info.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type exp =
4040
| RegExp of RegExp.t
4141
]}
4242
*)
43+
| Js_raw_json
4344
| Js_exp_unknown
4445

4546

jscomp/core/lam_compile_const.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ let translate_arg_cst (cst : External_arg_spec.cst) =
129129
E.str i
130130
| Arg_js_null -> E.nil
131131
| Arg_js_json s
132-
-> E.raw_js_code (Exp Js_exp_unknown) s
132+
-> E.raw_js_code (Exp Js_raw_json) s
133133

134134
| Arg_js_true -> E.bool true
135135
| Arg_js_false -> E.bool false

jscomp/test/bs_node_string_buffer_test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ function f(str) {
99
"buffer",
1010
Buffer.isBuffer(match[1])
1111
]);
12-
return ;
1312
} else {
1413
console.log(/* tuple */[
1514
"string",
1615
match[1]
1716
]);
18-
return ;
1917
}
18+
2019
}
2120

2221
f("xx");

jscomp/test/gpr_1891_test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ var Curry = require("../../lib/js/curry.js");
55
function foo(x) {
66
if (typeof x === "number" || x[0] !== 3505894 || x[1] !== 3) {
77
console.log("2");
8-
return ;
98
} else {
109
console.log("1");
11-
return ;
1210
}
11+
1312
}
1413

1514
function foo2(x) {
@@ -39,11 +38,10 @@ function foo4(x, h) {
3938
function foo5(x) {
4039
if (typeof x === "number" || x[0] !== 3505894 || x[1] !== 3) {
4140
console.log("x");
42-
return ;
4341
} else {
4442
console.log("hi");
45-
return ;
4643
}
44+
4745
}
4846

4947
exports.foo = foo;

jscomp/test/gpr_3875_test.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,27 @@ function compilerBug(a, b, c, f) {
2525
if (b === undefined) {
2626
if (c) {
2727
result.contents = "No x, c is true";
28-
return ;
2928
} else {
3029
result.contents = "No x, c is false";
31-
return ;
3230
}
31+
return ;
3332
}
3433
if (b !== "x") {
3534
if (c) {
3635
result.contents = "No x, c is true";
37-
return ;
3836
} else {
3937
result.contents = "No x, c is false";
40-
return ;
4138
}
39+
return ;
4240
}
4341

4442
}
4543
if (Curry._1(f, undefined)) {
4644
result.contents = "Some x, f returns true";
47-
return ;
4845
} else {
4946
result.contents = "Some x, f returns false";
50-
return ;
5147
}
48+
5249
}
5350

5451
var suites = {

jscomp/test/inline_record_test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ eq("File \"inline_record_test.ml\", line 51, characters 6-13", tmp, 3);
7979
function ff(x) {
8080
if (x.tag) {
8181
x[/* z */0] = x[/* z */0] + 2 | 0;
82-
return ;
8382
} else {
8483
x[/* x */0] = x[/* x */0] + 1 | 0;
85-
return ;
8684
}
85+
8786
}
8887

8988
var v4 = /* A0 */Block.__(0, [

jscomp/test/mario_game.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,11 +808,10 @@ function set_vel_to_speed(obj) {
808808
var match = obj.dir;
809809
if (match) {
810810
obj.vel.x = speed;
811-
return ;
812811
} else {
813812
obj.vel.x = -speed;
814-
return ;
815813
}
814+
816815
}
817816

818817
function make_type$2(t) {

jscomp/test/mt.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,10 @@ function from_promise_suites(name, suites) {
213213

214214
}), suites);
215215
}));
216-
return ;
217216
} else {
218217
console.log("promise suites");
219-
return ;
220218
}
219+
return ;
221220
}
222221

223222
}

0 commit comments

Comments
 (0)