@@ -34,31 +34,15 @@ let handle_config (config : Parsetree.expression option) =
3434 U. invalid_config config
3535 | None -> ()
3636
37- (* see #2337
38- TODO: relax it to allow (int -> int [@bs])
39- *)
40- let rec checkNotFunciton (ty : Parsetree.core_type ) =
41- match ty.ptyp_desc with
42- | Ptyp_poly (_ ,ty ) -> checkNotFunciton ty
43- | Ptyp_alias (ty ,_ ) -> checkNotFunciton ty
44- | Ptyp_arrow _ ->
45- Location. raise_errorf
46- ~loc: ty.ptyp_loc
47- " syntactic function type is not allowed when working with abstract bs.deriving, create a named type as work around"
48- | Ptyp_any
49- | Ptyp_var _
50- | Ptyp_tuple _
51- | Ptyp_constr _
52- | Ptyp_object _
53- | Ptyp_class _
54- | Ptyp_variant _
55- | Ptyp_package _
56- | Ptyp_extension _ -> ()
5737
5838
5939let get_optional_attrs =
6040 [Ast_attributes. bs_get; Ast_attributes. bs_return_undefined]
61- let get_attrs = [ Ast_attributes. bs_get ]
41+ (* * For this attributes, its type was wrapped as an option,
42+ so we can still reuse existing frame work
43+ *)
44+
45+ let get_attrs = [ Ast_attributes. bs_get_arity]
6246let set_attrs = [Ast_attributes. bs_set]
6347let handleTdcl (tdcl : Parsetree.type_declaration ) =
6448 let core_type = U. core_type_of_type_declaration tdcl in
@@ -88,31 +72,38 @@ let handleTdcl (tdcl : Parsetree.type_declaration) =
8872 pld_loc
8973 } :
9074 Parsetree. label_declaration ) (acc , maker , labels ) ->
91- let () = checkNotFunciton pld_type in
92- (* TODO: explain why *)
93- let prim, newLabel =
75+ let prim_as_name, newLabel =
9476 match Ast_attributes. iter_process_bs_string_as pld_attributes with
9577 | None ->
96- [ label_name] , pld_name
78+ label_name, pld_name
9779 | Some new_name ->
98- [ new_name] , {pld_name with txt = new_name}
80+ new_name, {pld_name with txt = new_name}
9981 in
100- let is_option = Ast_attributes. has_bs_optional pld_attributes in
101- let maker, getter_type =
102- if is_option then
82+ let prim = [prim_as_name] in
83+ let is_optional = Ast_attributes. has_bs_optional pld_attributes in
84+ let maker, getter_declaration =
85+ if is_optional then
10386 let optional_type = Ast_core_type. lift_option_type pld_type in
104- Ast_core_type. opt_arrow pld_loc label_name optional_type maker,
105- Typ. arrow ~loc " " core_type optional_type
87+ (Ast_core_type. opt_arrow pld_loc label_name optional_type maker,
88+ Val. mk pld_name
89+ ~attrs: get_optional_attrs ~prim
90+ (Typ. arrow ~loc " " core_type optional_type)
91+ )
10692 else
10793 Typ. arrow ~loc: pld_loc label_name pld_type maker,
108- Typ. arrow ~loc " " core_type pld_type
94+ Val. mk pld_name ~attrs: get_attrs
95+ ~prim: (
96+ [" " ; (* Not needed actually*)
97+ External_ffi_types. to_string
98+ (Ffi_bs (
99+ [{arg_type = Nothing ; arg_label = External_arg_spec. empty_label}],
100+ Return_identity ,
101+ Js_get {js_get_name = prim_as_name; js_get_scopes = [] }
102+ ))] )
103+ (Typ. arrow ~loc " " core_type pld_type)
109104 in
110105 let acc =
111- Val. mk pld_name
112- ~attrs: (
113- if is_option then get_optional_attrs
114- else get_attrs)
115- ~prim getter_type :: acc in
106+ getter_declaration :: acc in
116107 let is_current_field_mutable = pld_mutable = Mutable in
117108 let acc =
118109 if is_current_field_mutable then
@@ -130,7 +121,7 @@ let handleTdcl (tdcl : Parsetree.type_declaration) =
130121 else acc in
131122 acc,
132123 maker,
133- (is_option , newLabel)::labels
124+ (is_optional , newLabel)::labels
134125 ) label_declarations
135126 ([] ,
136127 (if has_optional_field then
0 commit comments