Skip to content

Commit 068fc53

Browse files
committed
add bs.return nullable support, no nested parens
1 parent b9b9f25 commit 068fc53

File tree

9 files changed

+44
-15
lines changed

9 files changed

+44
-15
lines changed

jscomp/bin/bsdep.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30910,6 +30910,7 @@ let process_external_attributes
3091030910
begin match txt with
3091130911
| "undefined_to_opt" -> Return_undefined_to_opt
3091230912
| "null_to_opt" -> Return_null_to_opt
30913+
| "nullable"
3091330914
| "null_undefined_to_opt" -> Return_null_undefined_to_opt
3091430915
| "identity" -> Return_identity
3091530916
| _ ->

jscomp/bin/bsppx.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12921,6 +12921,7 @@ let process_external_attributes
1292112921
begin match txt with
1292212922
| "undefined_to_opt" -> Return_undefined_to_opt
1292312923
| "null_to_opt" -> Return_null_to_opt
12924+
| "nullable"
1292412925
| "null_undefined_to_opt" -> Return_null_undefined_to_opt
1292512926
| "identity" -> Return_identity
1292612927
| _ ->

jscomp/bin/whole_compiler.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86373,13 +86373,16 @@ and
8637386373
then P.paren_group f 1 action
8637486374
else action ()
8637586375
| Is_null_undefined_to_boolean e ->
86376-
P.paren_group f 1 (fun _ ->
86376+
let action = (fun _ ->
8637786377
let cxt = expression 1 cxt f e in
8637886378
P.space f ;
8637986379
P.string f "==";
8638086380
P.space f ;
8638186381
P.string f L.null;
86382-
cxt)
86382+
cxt) in
86383+
if l > 0 then
86384+
P.paren_group f 1 action
86385+
else action ()
8638386386

8638486387
| Caml_not e ->
8638586388
expression_desc cxt l f (Bin (Minus, E.one_int_literal, e))
@@ -104068,6 +104071,7 @@ let process_external_attributes
104068104071
begin match txt with
104069104072
| "undefined_to_opt" -> Return_undefined_to_opt
104070104073
| "null_to_opt" -> Return_null_to_opt
104074+
| "nullable"
104071104075
| "null_undefined_to_opt" -> Return_null_undefined_to_opt
104072104076
| "identity" -> Return_identity
104073104077
| _ ->

jscomp/core/js_dump.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,13 +837,16 @@ and
837837
then P.paren_group f 1 action
838838
else action ()
839839
| Is_null_undefined_to_boolean e ->
840-
P.paren_group f 1 (fun _ ->
840+
let action = (fun _ ->
841841
let cxt = expression 1 cxt f e in
842842
P.space f ;
843843
P.string f "==";
844844
P.space f ;
845845
P.string f L.null;
846-
cxt)
846+
cxt) in
847+
if l > 0 then
848+
P.paren_group f 1 action
849+
else action ()
847850

848851
| Caml_not e ->
849852
expression_desc cxt l f (Bin (Minus, E.one_int_literal, e))

jscomp/syntax/ast_external_attributes.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ let process_external_attributes
350350
begin match txt with
351351
| "undefined_to_opt" -> Return_undefined_to_opt
352352
| "null_to_opt" -> Return_null_to_opt
353+
| "nullable"
353354
| "null_undefined_to_opt" -> Return_null_undefined_to_opt
354355
| "identity" -> Return_identity
355356
| _ ->

jscomp/test/bs_splice_partial.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ function test_hi(x) {
1212
}
1313
}
1414

15+
function test_hi__2(x) {
16+
var match = x.hi__2();
17+
if (match == null) {
18+
return 1;
19+
} else {
20+
return 2;
21+
}
22+
}
23+
1524
function test_cb(x) {
1625
Curry._1(x.cb("hI", 1, 2, 3), 3);
1726
Curry._1(x.cb("hI", 1, 2, 3), 3);
@@ -23,7 +32,8 @@ function f(x) {
2332
return /* () */0;
2433
}
2534

26-
exports.test_hi = test_hi;
27-
exports.test_cb = test_cb;
28-
exports.f = f;
35+
exports.test_hi = test_hi;
36+
exports.test_hi__2 = test_hi__2;
37+
exports.test_cb = test_cb;
38+
exports.f = f;
2939
/* No side effect */

jscomp/test/bs_splice_partial.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ let test_hi x =
3535
| Some y -> Js.log y ; 2
3636

3737

38+
external hi__2 : int array -> int option = ""
39+
[@@bs.splice] [@@bs.return nullable ]
40+
[@@bs.send.pipe:int]
41+
42+
let test_hi__2 x =
43+
match x |> hi__2 [||]with
44+
| None -> 1
45+
| Some _ -> 2
46+
3847
type id = int -> int
3948

4049
external cb : string -> int array -> id = ""

jscomp/test/return_check.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function f_null(xs, i) {
7373

7474
function f_null_undefined(xs, i) {
7575
var match = xs[i];
76-
if ((match == null)) {
76+
if (match == null) {
7777
throw [
7878
Caml_builtin_exceptions.assert_failure,
7979
[

jscomp/test/test_zero_nullable.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,15 @@ var Test_def = /* module */[
196196
];
197197

198198
function f1$2(x) {
199-
if ((x == null)) {
199+
if (x == null) {
200200
return 3;
201201
} else {
202202
return x + 1 | 0;
203203
}
204204
}
205205

206206
function f2$2(x) {
207-
if ((x == null)) {
207+
if (x == null) {
208208
return 3;
209209
} else {
210210
return x + 1 | 0;
@@ -213,7 +213,7 @@ function f2$2(x) {
213213

214214
function f5$2(h, _) {
215215
var u = Curry._1(h, 32);
216-
if ((u == null)) {
216+
if (u == null) {
217217
return 3;
218218
} else {
219219
return u + 1 | 0;
@@ -223,7 +223,7 @@ function f5$2(h, _) {
223223
function f4$2(h, x) {
224224
var u = Curry._1(h, 32);
225225
var v = 32 + x | 0;
226-
if ((u == null)) {
226+
if (u == null) {
227227
return 1 + v | 0;
228228
} else {
229229
return u + 1 | 0;
@@ -239,9 +239,9 @@ function f7$2(x) {
239239
}
240240

241241
function f8$2(x) {
242-
if ((x == null)) {
242+
if (x == null) {
243243
return 2;
244-
} else if ((x == null)) {
244+
} else if (x == null) {
245245
return 1;
246246
} else {
247247
return 0;
@@ -251,7 +251,7 @@ function f8$2(x) {
251251
var u$2 = f8$2(/* None */0);
252252

253253
function f9$2(x) {
254-
if ((x == null)) {
254+
if (x == null) {
255255
return /* None */0;
256256
} else {
257257
return [x];

0 commit comments

Comments
 (0)