@@ -7,7 +7,12 @@ and exportModuleValue =
77 | M of exportModuleItem
88
99type exportModuleItems = (string , exportModuleItem ) Hashtbl .t
10- type types = {typeForValue : type_ ; typeForType : type_ ; needsConversion : bool }
10+
11+ type types = {
12+ typeForValue : type_ ;
13+ typeForType : type_ ;
14+ needsConversion : bool ;
15+ }
1116
1217type fieldInfo = {
1318 fieldForValue : field ;
@@ -18,37 +23,37 @@ type fieldInfo = {
1823let rec exportModuleValueToType ~config exportModuleValue =
1924 match exportModuleValue with
2025 | S (s , type_ , converter ) ->
21- {
22- typeForValue = ident s;
23- typeForType = type_;
24- needsConversion =
25- not (converter |> Converter. converterIsIdentity ~config ~to JS:true );
26- }
26+ {
27+ typeForValue = ident s;
28+ typeForType = type_;
29+ needsConversion =
30+ not (converter |> Converter. converterIsIdentity ~config ~to JS:true );
31+ }
2732 | M exportModuleItem ->
28- let fieldsInfo = exportModuleItem |> exportModuleItemToFields ~config in
29- let fieldsForValue =
30- fieldsInfo |> List. map (fun {fieldForValue} -> fieldForValue)
31- in
32- let fieldsForType =
33- fieldsInfo |> List. map (fun {fieldForType} -> fieldForType)
34- in
35- let needsConversion =
36- fieldsInfo
37- |> List. fold_left
38- (fun acc {needsConversion} -> acc || needsConversion)
39- false
40- in
41- {
42- typeForValue = Object (Open , fieldsForValue);
43- typeForType = Object (Open , fieldsForType);
44- needsConversion;
45- }
33+ let fieldsInfo = exportModuleItem |> exportModuleItemToFields ~config in
34+ let fieldsForValue =
35+ fieldsInfo |> List. map (fun { fieldForValue } -> fieldForValue)
36+ in
37+ let fieldsForType =
38+ fieldsInfo |> List. map (fun { fieldForType } -> fieldForType)
39+ in
40+ let needsConversion =
41+ fieldsInfo
42+ |> List. fold_left
43+ (fun acc { needsConversion } -> acc || needsConversion)
44+ false
45+ in
46+ {
47+ typeForValue = Object (Open , fieldsForValue);
48+ typeForType = Object (Open , fieldsForType);
49+ needsConversion;
50+ }
4651
4752and exportModuleItemToFields =
4853 (fun ~config exportModuleItem ->
4954 Hashtbl. fold
5055 (fun fieldName exportModuleValue fields ->
51- let {typeForValue; typeForType; needsConversion} =
56+ let { typeForValue; typeForType; needsConversion } =
5257 exportModuleValue |> exportModuleValueToType ~config
5358 in
5459 let fieldForType =
@@ -60,47 +65,48 @@ and exportModuleItemToFields =
6065 type_ = typeForType;
6166 }
6267 in
63- let fieldForValue = {fieldForType with type_ = typeForValue} in
64- {fieldForValue; fieldForType; needsConversion} :: fields)
68+ let fieldForValue = { fieldForType with type_ = typeForValue } in
69+ { fieldForValue; fieldForType; needsConversion } :: fields)
6570 exportModuleItem []
6671 : config:Config. t -> exportModuleItem -> fieldInfo list )
6772
6873let rec extendExportModuleItem x ~converter
6974 ~(exportModuleItem : exportModuleItem ) ~type_ ~valueName =
7075 match x with
7176 | [] -> ()
72- | [fieldName] ->
73- Hashtbl. replace exportModuleItem fieldName (S (valueName, type_, converter))
77+ | [ fieldName ] ->
78+ Hashtbl. replace exportModuleItem fieldName
79+ (S (valueName, type_, converter))
7480 | fieldName :: rest ->
75- let innerExportModuleItem =
76- match Hashtbl. find exportModuleItem fieldName with
77- | M innerExportModuleItem -> innerExportModuleItem
78- | S _ -> assert false
79- | exception Not_found ->
80- let innerExportModuleItem = Hashtbl. create 1 in
81- Hashtbl. replace exportModuleItem fieldName (M innerExportModuleItem);
82- innerExportModuleItem
83- in
84- rest
85- |> extendExportModuleItem ~converter ~export ModuleItem:innerExportModuleItem
86- ~value Name ~type_
81+ let innerExportModuleItem =
82+ match Hashtbl. find exportModuleItem fieldName with
83+ | M innerExportModuleItem -> innerExportModuleItem
84+ | S _ -> assert false
85+ | exception Not_found ->
86+ let innerExportModuleItem = Hashtbl. create 1 in
87+ Hashtbl. replace exportModuleItem fieldName (M innerExportModuleItem);
88+ innerExportModuleItem
89+ in
90+ rest
91+ |> extendExportModuleItem ~converter
92+ ~export ModuleItem:innerExportModuleItem ~value Name ~type_
8793
8894let extendExportModuleItems x ~converter
8995 ~(exportModuleItems : exportModuleItems ) ~type_ ~valueName =
9096 match x with
9197 | [] -> assert false
92- | [_valueName] -> ()
98+ | [ _valueName ] -> ()
9399 | moduleName :: rest ->
94- let exportModuleItem =
95- match Hashtbl. find exportModuleItems moduleName with
96- | exportModuleItem -> exportModuleItem
97- | exception Not_found ->
98- let exportModuleItem = Hashtbl. create 1 in
99- Hashtbl. replace exportModuleItems moduleName exportModuleItem;
100- exportModuleItem
101- in
102- rest
103- |> extendExportModuleItem ~converter ~export ModuleItem ~type_ ~value Name
100+ let exportModuleItem =
101+ match Hashtbl. find exportModuleItems moduleName with
102+ | exportModuleItem -> exportModuleItem
103+ | exception Not_found ->
104+ let exportModuleItem = Hashtbl. create 1 in
105+ Hashtbl. replace exportModuleItems moduleName exportModuleItem;
106+ exportModuleItem
107+ in
108+ rest
109+ |> extendExportModuleItem ~converter ~export ModuleItem ~type_ ~value Name
104110
105111let createModuleItemsEmitter =
106112 (fun () -> Hashtbl. create 1 : unit -> exportModuleItems)
@@ -114,7 +120,7 @@ let emitAllModuleItems ~config ~emitters ~fileName
114120 emitters
115121 |> rev_fold
116122 (fun moduleName exportModuleItem emitters ->
117- let {typeForType; needsConversion} =
123+ let { typeForType; needsConversion } =
118124 M exportModuleItem |> exportModuleValueToType ~config
119125 in
120126 if ! Debug. codeItems then
0 commit comments