Skip to content

Commit c312081

Browse files
committed
format
1 parent 0a1d3bd commit c312081

File tree

3 files changed

+67
-76
lines changed

3 files changed

+67
-76
lines changed

jscomp/gentype/EmitType.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let outputFileSuffix ~(config : Config.t) =
2828
let generatedModuleExtension ~config = generatedFilesExtension ~config
2929
let shimExtension = ".shim.ts"
3030

31-
let interfaceName ~(config: Config.t) name =
31+
let interfaceName ~(config : Config.t) name =
3232
match config.exportInterfaces with true -> "I" ^ name | false -> name
3333

3434
let typeAny = ident ~builtin:true "any"
@@ -73,8 +73,8 @@ let isTypeReactRef ~fields =
7373
let isTypeFunctionComponent ~fields type_ =
7474
type_ |> isTypeReactElement && not (isTypeReactRef ~fields)
7575

76-
let rec renderType ~(config: Config.t) ?(indent = None) ~typeNameIsInterface ~inFunType
77-
type0 =
76+
let rec renderType ~(config : Config.t) ?(indent = None) ~typeNameIsInterface
77+
~inFunType type0 =
7878
match type0 with
7979
| Array (t, arrayKind) ->
8080
let typeIsSimple =
@@ -280,8 +280,8 @@ let emitExportConst ~early ?(comment = "") ~config ?(docString = "") ~emitters
280280
let emitExportDefault ~emitters name =
281281
"export default " ^ name ^ ";" |> Emitters.export ~emitters
282282
283-
let emitExportType ~(config: Config.t) ~emitters ~nameAs ~opaque ~type_ ~typeNameIsInterface
284-
~typeVars resolvedTypeName =
283+
let emitExportType ~(config : Config.t) ~emitters ~nameAs ~opaque ~type_
284+
~typeNameIsInterface ~typeVars resolvedTypeName =
285285
let typeParamsString = EmitText.genericsString ~typeVars in
286286
let isInterface = resolvedTypeName |> typeNameIsInterface in
287287
let resolvedTypeName =
@@ -334,8 +334,8 @@ let emitImportValueAsEarly ~emitters ~name ~nameAs importPath =
334334
^ "';"
335335
|> Emitters.requireEarly ~emitters
336336
337-
let emitRequire ~importedValueOrComponent ~early ~emitters ~(config: Config.t) ~moduleName
338-
importPath =
337+
let emitRequire ~importedValueOrComponent ~early ~emitters ~(config : Config.t)
338+
~moduleName importPath =
339339
let commentBeforeRequire =
340340
match importedValueOrComponent with
341341
| true -> "// tslint:disable-next-line:no-var-requires\n"

jscomp/gentype/ExportModule.ml

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ and exportModuleValue =
77
| M of exportModuleItem
88

99
type 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

1217
type fieldInfo = {
1318
fieldForValue : field;
@@ -18,37 +23,37 @@ type fieldInfo = {
1823
let 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 ~toJS:true);
26-
}
26+
{
27+
typeForValue = ident s;
28+
typeForType = type_;
29+
needsConversion =
30+
not (converter |> Converter.converterIsIdentity ~config ~toJS: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

4752
and 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

6873
let 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 ~exportModuleItem:innerExportModuleItem
86-
~valueName ~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+
~exportModuleItem:innerExportModuleItem ~valueName ~type_
8793

8894
let 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 ~exportModuleItem ~type_ ~valueName
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 ~exportModuleItem ~type_ ~valueName
104110

105111
let 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

jscomp/gentype/Runtime.mli

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
open GenTypeCommon
22

33
type recordGen
4-
54
type recordValue
6-
75
type moduleItem
8-
96
type moduleAccessPath = Root of string | Dot of moduleAccessPath * moduleItem
107

118
val accessVariant : index:int -> string -> string
12-
139
val checkMutableObjectField : previousName:string -> name:string -> bool
14-
1510
val default : string
16-
1711
val emitModuleAccessPath : config:Config.t -> moduleAccessPath -> string
18-
1912
val emitJSVariantGetLabel : polymorphic:bool -> string -> string
20-
2113
val emitJSVariantGetPayload : polymorphic:bool -> string -> string
2214

2315
val emitJSVariantWithPayload :
@@ -34,17 +26,10 @@ val emitVariantWithPayload :
3426
inlineRecord:bool -> label:string -> polymorphic:bool -> string list -> string
3527

3628
val isMutableObjectField : string -> bool
37-
3829
val mangleObjectField : string -> string
39-
4030
val newModuleItem : name:string -> moduleItem
41-
4231
val newRecordValue : unboxed:bool -> recordGen -> recordValue
43-
4432
val recordGen : unit -> recordGen
45-
4633
val recordValueToString : recordValue -> string
47-
4834
val jsVariantTag : polymorphic:bool -> string
49-
5035
val jsVariantValue : polymorphic:bool -> string

0 commit comments

Comments
 (0)