Skip to content

Commit ffd2122

Browse files
committed
clean up
1 parent 54dd5c7 commit ffd2122

File tree

9 files changed

+100
-51
lines changed

9 files changed

+100
-51
lines changed

jscomp/syntax/ast_attributes.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ let iter_process_bs_int_as (attrs : t) =
307307
| _ -> ()
308308
) ; !st
309309

310+
type as_const_payload =
311+
| Int of int
312+
| Str of string
313+
| Json_str of string
310314

311315
let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
312316
let st = ref None in
@@ -322,15 +326,15 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
322326
| None ->
323327
begin match Ast_payload.is_single_string payload with
324328
| Some (s,None) ->
325-
st := Some (`Str (s))
329+
st := Some (Str (s))
326330
| Some (s, Some "json") ->
327-
st := Some (`Json_str s )
331+
st := Some (Json_str s )
328332
| None | Some (_, Some _) ->
329333
Bs_syntaxerr.err loc Expect_int_or_string_or_json_literal
330334

331335
end
332336
| Some v->
333-
st := (Some (`Int v))
337+
st := (Some (Int v))
334338
)
335339
else
336340
Bs_syntaxerr.err loc Duplicated_bs_as

jscomp/syntax/ast_attributes.mli

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,15 @@ val has_bs_optional :
8181
val iter_process_bs_int_as :
8282
t -> int option
8383

84+
type as_const_payload =
85+
| Int of int
86+
| Str of string
87+
| Json_str of string
88+
8489

8590
val iter_process_bs_string_or_int_as :
8691
t ->
87-
[ `Int of int
88-
| `Str of string
89-
| `Json_str of string ] option
92+
as_const_payload option
9093

9194

9295
val process_derive_type :

jscomp/syntax/ast_external_process.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ let refine_arg_type ~(nolabel:bool) (ptyp : Ast_core_type.t)
111111
match result with
112112
| None ->
113113
Bs_syntaxerr.err ptyp.ptyp_loc Invalid_underscore_type_in_external
114-
| Some (`Int i) ->
114+
| Some (Int i) ->
115+
(* This type is used in bs.obj only to construct obj type*)
115116
Ast_literal.type_int ~loc:ptyp.ptyp_loc (), Arg_cst(External_arg_spec.cst_int i)
116-
| Some (`Str i)->
117+
| Some (Str i)->
117118
Ast_literal.type_string ~loc:ptyp.ptyp_loc (), Arg_cst (External_arg_spec.cst_string i)
118-
| Some (`Json_str s) ->
119+
| Some (Json_str s) ->
120+
(* FIXME: This seems to be wrong in bs.obj, we should disable such payload in bs.obj *)
119121
Ast_literal.type_string ~loc:ptyp.ptyp_loc (), Arg_cst (External_arg_spec.cst_json ptyp.ptyp_loc s)
120122
else (* ([`a|`b] [@bs.string]) *)
121123
ptyp, spec_of_ptyp nolabel ptyp

jscomp/test/prepend_data_ffi.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ process.on((function (i) {
3030
xx(3, 3, "xxx", "a", "b");
3131

3232
function f(x) {
33-
x.xx(110, [
33+
x.xx(114, [
3434
1,
3535
2,
3636
3
3737
]);
38-
x.xx(111, 3, "xxx", [
38+
x.xx(115, 3, "xxx", [
3939
1,
4040
2,
4141
3
4242
]);
43-
x.xx(112, 3, "xxx", 1, 2, 3);
44-
x.xx(113, 3, "xxx", 0, "b", 1, 2, 3, 4, 5);
45-
x.xx(114, 3, true, false, "你好", ["你好",1,2,3], [{ "arr" : ["你好",1,2,3], "encoding" : "utf8"}], [{ "arr" : ["你好",1,2,3], "encoding" : "utf8"}], "xxx", 0, "yyy", "b", 1, 2, 3, 4, 5);
43+
x.xx(116, 3, "xxx", 1, 2, 3);
44+
x.xx(117, 3, "xxx", 0, "b", 1, 2, 3, 4, 5);
45+
x.xx(118, 3, true, false, "你好", ["你好",1,2,3], [{ "arr" : ["你好",1,2,3], "encoding" : "utf8"}], [{ "arr" : ["你好",1,2,3], "encoding" : "utf8"}], "xxx", 0, "yyy", "b", 1, 2, 3, 4, 5);
4646

4747
}
4848

jscomp/test/prepend_data_ffi.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ external config1 : stdio:(_ [@bs.as "inherit"]) -> v:int -> unit -> _ = "" [@@
55
let v1 : config1_expect = config1 ~v:3 ()
66

77
type config2_expect = < stdio : int ; v : int > Js.t
8-
external config2 : stdio:(_ [@bs.as 1 ]) -> v:int -> unit -> _ = "" [@@bs.obj]
98

9+
external config2 : stdio:(_ [@bs.as 1 ]) -> v:int -> unit -> _ = "" [@@bs.obj]
1010
let v2 : config2_expect = config2 ~v:2 ()
1111

12+
#if 0 then
13+
external config3 : stdio:(_ [@bs.as {json|null|json}]) -> v:int -> unit -> _ = "" [@@bs.obj]
14+
let v_3 = config3 ~v:33 ()
15+
#end
1216

1317
external on_exit :
1418
(_ [@bs.as "exit"]) ->

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -402019,12 +402019,15 @@ val has_bs_optional :
402019402019
val iter_process_bs_int_as :
402020402020
t -> int option
402021402021

402022+
type as_const_payload =
402023+
| Int of int
402024+
| Str of string
402025+
| Json_str of string
402026+
402022402027

402023402028
val iter_process_bs_string_or_int_as :
402024402029
t ->
402025-
[ `Int of int
402026-
| `Str of string
402027-
| `Json_str of string ] option
402030+
as_const_payload option
402028402031

402029402032

402030402033
val process_derive_type :
@@ -402359,6 +402362,10 @@ let iter_process_bs_int_as (attrs : t) =
402359402362
| _ -> ()
402360402363
) ; !st
402361402364

402365+
type as_const_payload =
402366+
| Int of int
402367+
| Str of string
402368+
| Json_str of string
402362402369

402363402370
let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
402364402371
let st = ref None in
@@ -402374,15 +402381,15 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
402374402381
| None ->
402375402382
begin match Ast_payload.is_single_string payload with
402376402383
| Some (s,None) ->
402377-
st := Some (`Str (s))
402384+
st := Some (Str (s))
402378402385
| Some (s, Some "json") ->
402379-
st := Some (`Json_str s )
402386+
st := Some (Json_str s )
402380402387
| None | Some (_, Some _) ->
402381402388
Bs_syntaxerr.err loc Expect_int_or_string_or_json_literal
402382402389

402383402390
end
402384402391
| Some v->
402385-
st := (Some (`Int v))
402392+
st := (Some (Int v))
402386402393
)
402387402394
else
402388402395
Bs_syntaxerr.err loc Duplicated_bs_as
@@ -406008,11 +406015,13 @@ let refine_arg_type ~(nolabel:bool) (ptyp : Ast_core_type.t)
406008406015
match result with
406009406016
| None ->
406010406017
Bs_syntaxerr.err ptyp.ptyp_loc Invalid_underscore_type_in_external
406011-
| Some (`Int i) ->
406018+
| Some (Int i) ->
406019+
(* This type is used in bs.obj only to construct obj type*)
406012406020
Ast_literal.type_int ~loc:ptyp.ptyp_loc (), Arg_cst(External_arg_spec.cst_int i)
406013-
| Some (`Str i)->
406021+
| Some (Str i)->
406014406022
Ast_literal.type_string ~loc:ptyp.ptyp_loc (), Arg_cst (External_arg_spec.cst_string i)
406015-
| Some (`Json_str s) ->
406023+
| Some (Json_str s) ->
406024+
(* FIXME: This seems to be wrong in bs.obj, we should disable such payload in bs.obj *)
406016406025
Ast_literal.type_string ~loc:ptyp.ptyp_loc (), Arg_cst (External_arg_spec.cst_json ptyp.ptyp_loc s)
406017406026
else (* ([`a|`b] [@bs.string]) *)
406018406027
ptyp, spec_of_ptyp nolabel ptyp

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -402019,12 +402019,15 @@ val has_bs_optional :
402019402019
val iter_process_bs_int_as :
402020402020
t -> int option
402021402021

402022+
type as_const_payload =
402023+
| Int of int
402024+
| Str of string
402025+
| Json_str of string
402026+
402022402027

402023402028
val iter_process_bs_string_or_int_as :
402024402029
t ->
402025-
[ `Int of int
402026-
| `Str of string
402027-
| `Json_str of string ] option
402030+
as_const_payload option
402028402031

402029402032

402030402033
val process_derive_type :
@@ -402359,6 +402362,10 @@ let iter_process_bs_int_as (attrs : t) =
402359402362
| _ -> ()
402360402363
) ; !st
402361402364

402365+
type as_const_payload =
402366+
| Int of int
402367+
| Str of string
402368+
| Json_str of string
402362402369

402363402370
let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
402364402371
let st = ref None in
@@ -402374,15 +402381,15 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
402374402381
| None ->
402375402382
begin match Ast_payload.is_single_string payload with
402376402383
| Some (s,None) ->
402377-
st := Some (`Str (s))
402384+
st := Some (Str (s))
402378402385
| Some (s, Some "json") ->
402379-
st := Some (`Json_str s )
402386+
st := Some (Json_str s )
402380402387
| None | Some (_, Some _) ->
402381402388
Bs_syntaxerr.err loc Expect_int_or_string_or_json_literal
402382402389

402383402390
end
402384402391
| Some v->
402385-
st := (Some (`Int v))
402392+
st := (Some (Int v))
402386402393
)
402387402394
else
402388402395
Bs_syntaxerr.err loc Duplicated_bs_as
@@ -406008,11 +406015,13 @@ let refine_arg_type ~(nolabel:bool) (ptyp : Ast_core_type.t)
406008406015
match result with
406009406016
| None ->
406010406017
Bs_syntaxerr.err ptyp.ptyp_loc Invalid_underscore_type_in_external
406011-
| Some (`Int i) ->
406018+
| Some (Int i) ->
406019+
(* This type is used in bs.obj only to construct obj type*)
406012406020
Ast_literal.type_int ~loc:ptyp.ptyp_loc (), Arg_cst(External_arg_spec.cst_int i)
406013-
| Some (`Str i)->
406021+
| Some (Str i)->
406014406022
Ast_literal.type_string ~loc:ptyp.ptyp_loc (), Arg_cst (External_arg_spec.cst_string i)
406015-
| Some (`Json_str s) ->
406023+
| Some (Json_str s) ->
406024+
(* FIXME: This seems to be wrong in bs.obj, we should disable such payload in bs.obj *)
406016406025
Ast_literal.type_string ~loc:ptyp.ptyp_loc (), Arg_cst (External_arg_spec.cst_json ptyp.ptyp_loc s)
406017406026
else (* ([`a|`b] [@bs.string]) *)
406018406027
ptyp, spec_of_ptyp nolabel ptyp

lib/4.06.1/unstable/native_ppx.ml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15532,12 +15532,15 @@ val has_bs_optional :
1553215532
val iter_process_bs_int_as :
1553315533
t -> int option
1553415534

15535+
type as_const_payload =
15536+
| Int of int
15537+
| Str of string
15538+
| Json_str of string
15539+
1553515540

1553615541
val iter_process_bs_string_or_int_as :
1553715542
t ->
15538-
[ `Int of int
15539-
| `Str of string
15540-
| `Json_str of string ] option
15543+
as_const_payload option
1554115544

1554215545

1554315546
val process_derive_type :
@@ -15872,6 +15875,10 @@ let iter_process_bs_int_as (attrs : t) =
1587215875
| _ -> ()
1587315876
) ; !st
1587415877

15878+
type as_const_payload =
15879+
| Int of int
15880+
| Str of string
15881+
| Json_str of string
1587515882

1587615883
let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
1587715884
let st = ref None in
@@ -15887,15 +15894,15 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
1588715894
| None ->
1588815895
begin match Ast_payload.is_single_string payload with
1588915896
| Some (s,None) ->
15890-
st := Some (`Str (s))
15897+
st := Some (Str (s))
1589115898
| Some (s, Some "json") ->
15892-
st := Some (`Json_str s )
15899+
st := Some (Json_str s )
1589315900
| None | Some (_, Some _) ->
1589415901
Bs_syntaxerr.err loc Expect_int_or_string_or_json_literal
1589515902

1589615903
end
1589715904
| Some v->
15898-
st := (Some (`Int v))
15905+
st := (Some (Int v))
1589915906
)
1590015907
else
1590115908
Bs_syntaxerr.err loc Duplicated_bs_as
@@ -19304,11 +19311,13 @@ let refine_arg_type ~(nolabel:bool) (ptyp : Ast_core_type.t)
1930419311
match result with
1930519312
| None ->
1930619313
Bs_syntaxerr.err ptyp.ptyp_loc Invalid_underscore_type_in_external
19307-
| Some (`Int i) ->
19314+
| Some (Int i) ->
19315+
(* This type is used in bs.obj only to construct obj type*)
1930819316
Ast_literal.type_int ~loc:ptyp.ptyp_loc (), Arg_cst(External_arg_spec.cst_int i)
19309-
| Some (`Str i)->
19317+
| Some (Str i)->
1931019318
Ast_literal.type_string ~loc:ptyp.ptyp_loc (), Arg_cst (External_arg_spec.cst_string i)
19311-
| Some (`Json_str s) ->
19319+
| Some (Json_str s) ->
19320+
(* FIXME: This seems to be wrong in bs.obj, we should disable such payload in bs.obj *)
1931219321
Ast_literal.type_string ~loc:ptyp.ptyp_loc (), Arg_cst (External_arg_spec.cst_json ptyp.ptyp_loc s)
1931319322
else (* ([`a|`b] [@bs.string]) *)
1931419323
ptyp, spec_of_ptyp nolabel ptyp

lib/4.06.1/whole_compiler.ml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -405881,12 +405881,15 @@ val has_bs_optional :
405881405881
val iter_process_bs_int_as :
405882405882
t -> int option
405883405883

405884+
type as_const_payload =
405885+
| Int of int
405886+
| Str of string
405887+
| Json_str of string
405888+
405884405889

405885405890
val iter_process_bs_string_or_int_as :
405886405891
t ->
405887-
[ `Int of int
405888-
| `Str of string
405889-
| `Json_str of string ] option
405892+
as_const_payload option
405890405893

405891405894

405892405895
val process_derive_type :
@@ -406221,6 +406224,10 @@ let iter_process_bs_int_as (attrs : t) =
406221406224
| _ -> ()
406222406225
) ; !st
406223406226

406227+
type as_const_payload =
406228+
| Int of int
406229+
| Str of string
406230+
| Json_str of string
406224406231

406225406232
let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
406226406233
let st = ref None in
@@ -406236,15 +406243,15 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
406236406243
| None ->
406237406244
begin match Ast_payload.is_single_string payload with
406238406245
| Some (s,None) ->
406239-
st := Some (`Str (s))
406246+
st := Some (Str (s))
406240406247
| Some (s, Some "json") ->
406241-
st := Some (`Json_str s )
406248+
st := Some (Json_str s )
406242406249
| None | Some (_, Some _) ->
406243406250
Bs_syntaxerr.err loc Expect_int_or_string_or_json_literal
406244406251

406245406252
end
406246406253
| Some v->
406247-
st := (Some (`Int v))
406254+
st := (Some (Int v))
406248406255
)
406249406256
else
406250406257
Bs_syntaxerr.err loc Duplicated_bs_as
@@ -409747,11 +409754,13 @@ let refine_arg_type ~(nolabel:bool) (ptyp : Ast_core_type.t)
409747409754
match result with
409748409755
| None ->
409749409756
Bs_syntaxerr.err ptyp.ptyp_loc Invalid_underscore_type_in_external
409750-
| Some (`Int i) ->
409757+
| Some (Int i) ->
409758+
(* This type is used in bs.obj only to construct obj type*)
409751409759
Ast_literal.type_int ~loc:ptyp.ptyp_loc (), Arg_cst(External_arg_spec.cst_int i)
409752-
| Some (`Str i)->
409760+
| Some (Str i)->
409753409761
Ast_literal.type_string ~loc:ptyp.ptyp_loc (), Arg_cst (External_arg_spec.cst_string i)
409754-
| Some (`Json_str s) ->
409762+
| Some (Json_str s) ->
409763+
(* FIXME: This seems to be wrong in bs.obj, we should disable such payload in bs.obj *)
409755409764
Ast_literal.type_string ~loc:ptyp.ptyp_loc (), Arg_cst (External_arg_spec.cst_json ptyp.ptyp_loc s)
409756409765
else (* ([`a|`b] [@bs.string]) *)
409757409766
ptyp, spec_of_ptyp nolabel ptyp

0 commit comments

Comments
 (0)