11open GenTypeCommon
22
33type declaration_kind =
4- | RecordDeclarationFromTypes of
5- Types .label_declaration list * Types .record_representation
4+ | RecordDeclarationFromTypes of Types .label_declaration list
65 | GeneralDeclaration of Typedtree .core_type option
76 | GeneralDeclarationFromTypes of Types .type_expr option
87 (* * As the above, but from Types not Typedtree *)
@@ -86,16 +85,12 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
8685 in
8786 {CodeItem. import_types; export_from_type_declaration}
8887 in
89- let translate_label_declarations ?(inline = false ) ~record_representation
90- label_declarations =
91- let is_optional l =
92- match record_representation with
93- | Types. Record_optional_labels lbls -> List. mem l lbls
94- | _ -> false
95- in
88+ let translate_label_declarations ?(inline = false ) label_declarations =
9689 let field_translations =
9790 label_declarations
98- |> List. map (fun {Types. ld_id; ld_mutable; ld_type; ld_attributes} ->
91+ |> List. map
92+ (fun
93+ {Types. ld_id; ld_mutable; ld_optional; ld_type; ld_attributes} ->
9994 let name =
10095 rename_record_field ~attributes: ld_attributes
10196 ~name: (ld_id |> Ident. name)
@@ -107,25 +102,32 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
107102 in
108103 ( name,
109104 mutability,
105+ ld_optional,
110106 ld_type
111107 |> TranslateTypeExprFromTypes. translate_type_expr_from_types
112108 ~config ~type_env ,
113109 Annotation. doc_string_from_attrs ld_attributes ))
114110 in
115111 let dependencies =
116112 field_translations
117- |> List. map (fun (_ , _ , {TranslateTypeExprFromTypes. dependencies} , _ ) ->
113+ |> List. map
114+ (fun (_ , _ , _ , {TranslateTypeExprFromTypes. dependencies} , _ ) ->
118115 dependencies)
119116 |> List. concat
120117 in
121118 let fields =
122119 field_translations
123120 |> List. map
124121 (fun
125- (name , mutable_ , {TranslateTypeExprFromTypes. type_} , doc_string ) ->
122+ ( name ,
123+ mutable_ ,
124+ optional_ ,
125+ {TranslateTypeExprFromTypes. type_} ,
126+ doc_string )
127+ ->
126128 let optional, type1 =
127129 match type_ with
128- | Option type1 when is_optional name -> (Optional , type1)
130+ | Option type1 when optional_ -> (Optional , type1)
129131 | _ -> (Mandatory , type_)
130132 in
131133 {mutable_; name_js = name; optional; type_ = type1; doc_string})
@@ -216,10 +218,9 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
216218 in
217219 {translation with type_} |> handle_general_declaration
218220 |> return_type_declaration
219- | RecordDeclarationFromTypes (label_declarations, record_representation), None
220- ->
221+ | RecordDeclarationFromTypes label_declarations , None ->
221222 let {TranslateTypeExprFromTypes. dependencies; type_} =
222- label_declarations |> translate_label_declarations ~record_representation
223+ label_declarations |> translate_label_declarations
223224 in
224225 let import_types =
225226 dependencies
@@ -250,8 +251,7 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
250251 | Cstr_record label_declarations ->
251252 [
252253 label_declarations
253- |> translate_label_declarations ~inline: true
254- ~record_representation: Types. Record_regular ;
254+ |> translate_label_declarations ~inline: true ;
255255 ]
256256 in
257257 let arg_types =
@@ -334,8 +334,8 @@ let translate_type_declaration ~config ~output_file_relative ~resolver ~type_env
334334 in
335335 let declaration_kind =
336336 match typ_type.type_kind with
337- | Type_record (label_declarations , record_representation ) ->
338- RecordDeclarationFromTypes ( label_declarations, record_representation)
337+ | Type_record (label_declarations , _ ) ->
338+ RecordDeclarationFromTypes label_declarations
339339 | Type_variant constructor_declarations ->
340340 VariantDeclarationFromTypes constructor_declarations
341341 | Type_abstract -> GeneralDeclaration typ_manifest
0 commit comments