@@ -2,18 +2,21 @@ open GenTypeCommon
22
33type exportModuleItem = (string , exportModuleValue ) Hashtbl .t
44
5- and exportModuleValue = S of string * type_ | M of exportModuleItem
5+ and exportModuleValue =
6+ | S of {name : string ; type_ : type_ ; docString : DocString .t }
7+ | M of {exportModuleItem : exportModuleItem }
68
79type exportModuleItems = (string , exportModuleItem ) Hashtbl .t
810
9- type types = {typeForValue : type_ ; typeForType : type_ }
11+ type types = {typeForValue : type_ ; typeForType : type_ ; docString : DocString .t }
1012
1113type fieldInfo = {fieldForValue : field ; fieldForType : field }
1214
1315let rec exportModuleValueToType ~config exportModuleValue =
1416 match exportModuleValue with
15- | S (s , type_ ) -> {typeForValue = ident s; typeForType = type_}
16- | M exportModuleItem ->
17+ | S {name; type_; docString} ->
18+ {typeForValue = ident name; typeForType = type_; docString}
19+ | M {exportModuleItem} ->
1720 let fieldsInfo = exportModuleItem |> exportModuleItemToFields ~config in
1821 let fieldsForValue =
1922 fieldsInfo |> List. map (fun {fieldForValue} -> fieldForValue)
@@ -24,13 +27,14 @@ let rec exportModuleValueToType ~config exportModuleValue =
2427 {
2528 typeForValue = Object (Open , fieldsForValue);
2629 typeForType = Object (Open , fieldsForType);
30+ docString = DocString. empty;
2731 }
2832
2933and exportModuleItemToFields =
3034 (fun ~config exportModuleItem ->
3135 Hashtbl. fold
3236 (fun fieldName exportModuleValue fields ->
33- let {typeForValue; typeForType} =
37+ let {typeForValue; typeForType; docString } =
3438 exportModuleValue |> exportModuleValueToType ~config
3539 in
3640 let fieldForType =
@@ -39,36 +43,38 @@ and exportModuleItemToFields =
3943 nameJS = fieldName;
4044 optional = Mandatory ;
4145 type_ = typeForType;
42- docString = None ;
46+ docString;
4347 }
4448 in
4549 let fieldForValue = {fieldForType with type_ = typeForValue} in
4650 {fieldForValue; fieldForType} :: fields)
4751 exportModuleItem []
4852 : config:Config. t -> exportModuleItem -> fieldInfo list )
4953
50- let rec extendExportModuleItem x ~( exportModuleItem : exportModuleItem ) ~ type_
51- ~valueName =
54+ let rec extendExportModuleItem ~ docString x
55+ ~( exportModuleItem : exportModuleItem ) ~ type_ ~ valueName =
5256 match x with
5357 | [] -> ()
5458 | [fieldName] ->
55- Hashtbl. replace exportModuleItem fieldName (S (valueName, type_))
59+ Hashtbl. replace exportModuleItem fieldName
60+ (S {name = valueName; type_; docString})
5661 | fieldName :: rest ->
5762 let innerExportModuleItem =
5863 match Hashtbl. find exportModuleItem fieldName with
59- | M innerExportModuleItem -> innerExportModuleItem
64+ | M { exportModuleItem = innerExportModuleItem } -> innerExportModuleItem
6065 | S _ -> assert false
6166 | exception Not_found ->
6267 let innerExportModuleItem = Hashtbl. create 1 in
63- Hashtbl. replace exportModuleItem fieldName (M innerExportModuleItem);
68+ Hashtbl. replace exportModuleItem fieldName
69+ (M {exportModuleItem = innerExportModuleItem});
6470 innerExportModuleItem
6571 in
6672 rest
67- |> extendExportModuleItem ~export ModuleItem:innerExportModuleItem ~value Name
68- ~type_
73+ |> extendExportModuleItem ~doc String ~ export ModuleItem:innerExportModuleItem
74+ ~value Name ~ type_
6975
70- let extendExportModuleItems x ~( exportModuleItems : exportModuleItems ) ~ type_
71- ~valueName =
76+ let extendExportModuleItems x ~docString
77+ ~( exportModuleItems : exportModuleItems ) ~ type_ ~ valueName =
7278 match x with
7379 | [] -> assert false
7480 | [_valueName] -> ()
@@ -81,7 +87,8 @@ let extendExportModuleItems x ~(exportModuleItems : exportModuleItems) ~type_
8187 Hashtbl. replace exportModuleItems moduleName exportModuleItem;
8288 exportModuleItem
8389 in
84- rest |> extendExportModuleItem ~export ModuleItem ~type_ ~value Name
90+ rest
91+ |> extendExportModuleItem ~doc String ~export ModuleItem ~type_ ~value Name
8592
8693let createModuleItemsEmitter =
8794 (fun () -> Hashtbl. create 1 : unit -> exportModuleItems)
@@ -95,22 +102,23 @@ let emitAllModuleItems ~config ~emitters ~fileName
95102 emitters
96103 |> rev_fold
97104 (fun moduleName exportModuleItem emitters ->
98- let {typeForType} =
99- M exportModuleItem |> exportModuleValueToType ~config
105+ let {typeForType; docString } =
106+ M { exportModuleItem} |> exportModuleValueToType ~config
100107 in
101108 if ! Debug. codeItems then Log_. item " EmitModule %s @." moduleName;
102109 let emittedModuleItem =
103110 ModuleName. forInnerModule ~file Name ~inner ModuleName:moduleName
104111 |> ModuleName. toString
105112 in
106113 emittedModuleItem
107- |> EmitType. emitExportConst ~early: false ~config ~emitters
114+ |> EmitType. emitExportConst ~doc String ~ early:false ~config ~emitters
108115 ~name: moduleName ~type_: typeForType ~type NameIsInterface:(fun _ ->
109116 false ))
110117 exportModuleItems
111118
112- let extendExportModules ~(moduleItemsEmitter : exportModuleItems ) ~type_
113- resolvedName =
119+ let extendExportModules ~(moduleItemsEmitter : exportModuleItems ) ~docString
120+ ~ type_ resolvedName =
114121 resolvedName |> ResolvedName. toList
115122 |> extendExportModuleItems ~export ModuleItems:moduleItemsEmitter ~type_
123+ ~doc String
116124 ~value Name:(resolvedName |> ResolvedName. toString)
0 commit comments