@@ -17266,15 +17266,20 @@ type cst = private
17266
17266
17267
17267
type label = private
17268
17268
| Obj_label of {name : string}
17269
- (* | Obj_labelCst of {name : string ; cst : cst} *)
17270
17269
| Obj_empty
17271
17270
17272
17271
| Obj_optional of {name : string}
17273
17272
(* it will be ignored , side effect will be recorded *)
17274
17273
17274
+
17275
+
17275
17276
type attr =
17276
- | NullString of (Ast_compatible.hash_label * string) list (* `a does not have any value*)
17277
- | NonNullString of (Ast_compatible.hash_label * string) list (* `a of int *)
17277
+ | Poly_var of {
17278
+ has_payload : bool ;
17279
+ descr :
17280
+ (Ast_compatible.hash_label * string)
17281
+ list option
17282
+ }
17278
17283
| Int of (Ast_compatible.hash_label * int ) list (* ([`a | `b ] [@bs.int])*)
17279
17284
| Arg_cst of cst
17280
17285
| Fn_uncurry_arity of int (* annotated with [@bs.uncurry ] or [@bs.uncurry 2]*)
@@ -17363,9 +17368,16 @@ type label =
17363
17368
| Obj_optional of {name : string }
17364
17369
(* it will be ignored , side effect will be recorded *)
17365
17370
17371
+
17372
+
17366
17373
type attr =
17367
- | NullString of (Ast_compatible.hash_label * string) list (* `a does not have any value*)
17368
- | NonNullString of (Ast_compatible.hash_label * string) list (* `a of int *)
17374
+ | Poly_var of {
17375
+ has_payload : bool ;
17376
+ descr :
17377
+ (Ast_compatible.hash_label * string) list
17378
+ option
17379
+ }
17380
+ (* `a does not have any value*)
17369
17381
| Int of (Ast_compatible.hash_label * int ) list (* ([`a | `b ] [@bs.int])*)
17370
17382
| Arg_cst of cst
17371
17383
| Fn_uncurry_arity of int (* annotated with [@bs.uncurry ] or [@bs.uncurry 2]*)
@@ -17575,35 +17587,36 @@ let map_constructor_declarations_into_ints
17575
17587
*)
17576
17588
let map_row_fields_into_strings ptyp_loc
17577
17589
(row_fields : Parsetree.row_field list) : External_arg_spec.attr =
17590
+ let has_bs_as = ref false in
17578
17591
let case, result =
17579
17592
Ext_list.fold_right row_fields (`Nothing, []) (fun tag (nullary, acc) ->
17580
17593
match nullary, tag with
17581
17594
| (`Nothing | `Null),
17582
17595
Rtag (label, attrs, true, [])
17583
17596
->
17584
- begin match Ast_attributes.iter_process_bs_string_as attrs with
17597
+ let name =
17598
+ match Ast_attributes.iter_process_bs_string_as attrs with
17585
17599
| Some name ->
17586
- `Null, ((Ast_compatible.hash_label label, name) :: acc )
17587
-
17588
- | None ->
17589
- `Null, ((Ast_compatible.hash_label label, Ast_compatible.label_of_name label) :: acc )
17590
- end
17600
+ has_bs_as := true; name
17601
+ | None -> label.txt
17602
+ in `Null, (label.txt, name) :: acc
17591
17603
| (`Nothing | `NonNull), Rtag(label, attrs, false, ([ _ ]))
17592
17604
->
17593
- begin match Ast_attributes.iter_process_bs_string_as attrs with
17605
+ let name =
17606
+ match Ast_attributes.iter_process_bs_string_as attrs with
17594
17607
| Some name ->
17595
- `NonNull, ((Ast_compatible.hash_label label, name) :: acc)
17596
- | None ->
17597
- `NonNull, ((Ast_compatible.hash_label label, Ast_compatible.label_of_name label) :: acc)
17598
- end
17608
+ has_bs_as := true; name
17609
+ | None -> label.txt
17610
+ in `NonNull, (label.txt, name) :: acc
17599
17611
| _ -> Bs_syntaxerr.err ptyp_loc Invalid_bs_string_type
17600
17612
17601
17613
) in
17602
17614
match case with
17603
17615
| `Nothing -> Bs_syntaxerr.err ptyp_loc Invalid_bs_string_type
17604
- | `Null -> External_arg_spec.NullString result
17605
- | `NonNull -> NonNullString result
17606
-
17616
+ | `Null
17617
+ | `NonNull ->
17618
+ External_arg_spec.Poly_var {has_payload = case = `NonNull ;
17619
+ descr = if !has_bs_as then Some result else None }
17607
17620
17608
17621
let is_enum row_fields =
17609
17622
List.for_all (fun (x : Parsetree.row_field) ->
@@ -19700,7 +19713,7 @@ let process_obj
19700
19713
{obj_arg_label = External_arg_spec.obj_label s; obj_arg_type},
19701
19714
{param_type with ty = new_ty}::arg_types,
19702
19715
(({Asttypes.txt = name; loc}, [], Ast_literal.type_int ~loc ()) :: result_types)
19703
- | NullString _ ->
19716
+ | Poly_var { has_payload = false ; _} ->
19704
19717
let s = Lam_methname.translate name in
19705
19718
{obj_arg_label = External_arg_spec.obj_label s; obj_arg_type},
19706
19719
{param_type with ty = new_ty }::arg_types,
@@ -19709,7 +19722,7 @@ let process_obj
19709
19722
Location.raise_errorf ~loc
19710
19723
"The combination of [@@bs.obj], [@@bs.uncurry] is not supported yet"
19711
19724
| Extern_unit -> assert false
19712
- | NonNullString _
19725
+ | Poly_var { has_payload = true ; _}
19713
19726
->
19714
19727
Location.raise_errorf ~loc
19715
19728
"bs.obj label %s does not support such arg type" name
@@ -19733,7 +19746,7 @@ let process_obj
19733
19746
{obj_arg_label = External_arg_spec.optional s ; obj_arg_type },
19734
19747
param_type :: arg_types,
19735
19748
(({Asttypes.txt = name; loc}, [], Ast_comb.to_undefined_type loc @@ Ast_literal.type_int ~loc ()) :: result_types)
19736
- | NullString _ ->
19749
+ | Poly_var {has_payload = false ; _} ->
19737
19750
let s = Lam_methname.translate name in
19738
19751
{obj_arg_label = External_arg_spec.optional s ; obj_arg_type },
19739
19752
param_type::arg_types,
@@ -19745,7 +19758,7 @@ let process_obj
19745
19758
Location.raise_errorf ~loc
19746
19759
"The combination of [@@bs.obj], [@@bs.uncurry] is not supported yet"
19747
19760
| Extern_unit -> assert false
19748
- | NonNullString _
19761
+ | Poly_var {has_payload = true; _}
19749
19762
->
19750
19763
Location.raise_errorf ~loc
19751
19764
"bs.obj label %s does not support such arg type" name
@@ -20159,7 +20172,7 @@ let handle_attributes
20159
20172
| Optional s ->
20160
20173
let arg_type = get_opt_arg_type ~nolabel:false ty in
20161
20174
begin match arg_type with
20162
- | NonNullString _ ->
20175
+ | Poly_var {has_payload = true; _} ->
20163
20176
(* ?x:([`x of int ] [@bs.string]) does not make sense *)
20164
20177
Location.raise_errorf
20165
20178
~loc
0 commit comments