@glutinum/cli 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,13 @@
1
- import { printf, toFail, interpolate, toText, trimStart } from "../fable_modules/fable-library-js.4.14.0/String.js";
2
- import { class_type } from "../fable_modules/fable-library-js.4.14.0/Reflection.js";
1
+ import { printf, toFail, interpolate, toText, join, trimStart } from "../fable_modules/fable-library-js.4.14.0/String.js";
2
+ import { record_type, list_type, class_type } from "../fable_modules/fable-library-js.4.14.0/Reflection.js";
3
+ import { Record } from "../fable_modules/fable-library-js.4.14.0/Types.js";
4
+ import { FSharpTypeParameter_Create_Z6CFD3565, FSharpTypeAlias, FSharpEnum, FSharpEnumCase, FSharpStaticMemberInfo, FSharpAccessor, FSharpMapped, FSharpMember, FSharpMemberInfo, FSharpInterface, FSharpClass, FSharpConstructor, FSharpAccessibility, FSharpExplicitField, FSharpParameter, FSharpFunctionType, FSharpTypeReference, FSharpUnion, FSharpUnionCase, FSharpPrimitive, FSharpLiteral, FSharpCommentTypeParam, FSharpCommentParam, FSharpXmlDoc, FSharpAttribute, FSharpType, FSharpModule, FSharpXmlDoc_$reflection, FSharpAttribute_$reflection } from "./FsharpAST.js";
3
5
  import { empty as empty_1, singleton as singleton_1, collect, append, delay, toList } from "../fable_modules/fable-library-js.4.14.0/Seq.js";
4
- import { exists, append as append_1, forAll, tail, filter, choose, collect as collect_1, ofArray, sortBy, head as head_1, length, map, partition, singleton, empty, isEmpty } from "../fable_modules/fable-library-js.4.14.0/List.js";
5
- import { FSharpTypeParameter_Create_Z6CFD3565, FSharpTypeAlias, FSharpEnum, FSharpEnumCase, FSharpStaticMemberInfo, FSharpInterface, FSharpAccessor, FSharpMapped, FSharpMember, FSharpMemberInfo, FSharpClass, FSharpConstructor, FSharpAccessibility, FSharpExplicitField, FSharpParameter, FSharpFunctionType, FSharpTypeReference, FSharpUnion, FSharpUnionCase, FSharpPrimitive, FSharpLiteral, FSharpCommentParam, FSharpXmlDoc, FSharpAttribute, FSharpType, FSharpModule } from "./FsharpAST.js";
6
+ import { exists, filter, choose, collect as collect_1, ofArray, forAll, length, partition, sortBy, map, append as append_1, head as head_1, tail, singleton, empty, isEmpty } from "../fable_modules/fable-library-js.4.14.0/List.js";
6
7
  import { sanitizeNameWithResult, removeSurroundingQuotes, mapTypeNameToFableCoreAwareName, sanitizeName } from "./Utils/Naming.js";
7
- import { unwrap, map as map_1, defaultArg } from "../fable_modules/fable-library-js.4.14.0/Option.js";
8
- import { GlueType, GlueTypeUnion, GlueConstructor, GlueType__get_Name } from "./GlueAST.js";
8
+ import { unwrap, value as value_4, map as map_1, defaultArg } from "../fable_modules/fable-library-js.4.14.0/Option.js";
9
9
  import { int32ToString, safeHash, equals, comparePrimitives } from "../fable_modules/fable-library-js.4.14.0/Util.js";
10
+ import { GlueType, GlueTypeUnion, GlueConstructor, GlueType__get_Name } from "./GlueAST.js";
10
11
  import { warn, error } from "./Log.js";
11
12
  import { List_distinct } from "../fable_modules/fable-library-js.4.14.0/Seq2.js";
12
13
 
@@ -31,6 +32,18 @@ export function TransformContext_$ctor_Z535BF207(currentScopeName, parent) {
31
32
  return new TransformContext(currentScopeName, parent);
32
33
  }
33
34
 
35
+ export class TransformCommentResult extends Record {
36
+ constructor(ObsoleteAttributes, XmlDoc) {
37
+ super();
38
+ this.ObsoleteAttributes = ObsoleteAttributes;
39
+ this.XmlDoc = XmlDoc;
40
+ }
41
+ }
42
+
43
+ export function TransformCommentResult_$reflection() {
44
+ return record_type("Glutinum.Converter.Transform.TransformCommentResult", [], TransformCommentResult, () => [["ObsoleteAttributes", list_type(FSharpAttribute_$reflection())], ["XmlDoc", list_type(FSharpXmlDoc_$reflection())]]);
45
+ }
46
+
34
47
  export function TransformContext__get_FullName(__) {
35
48
  return __["FullName@"];
36
49
  }
@@ -81,44 +94,112 @@ function sanitizeNameAndPushScope(name, context) {
81
94
  }
82
95
 
83
96
  function transformComment(comment) {
84
- const patternInput = partition((_arg) => {
85
- if (_arg.tag === 3) {
86
- return true;
87
- }
88
- else {
89
- return false;
90
- }
91
- }, comment);
92
- return {
93
- ObsoleteAttributes: map((_arg_1) => {
94
- if (_arg_1.tag === 3) {
95
- return new FSharpAttribute(8, [_arg_1.fields[0]]);
97
+ const categorize = (acc_mut, comments_mut) => {
98
+ categorize:
99
+ while (true) {
100
+ const acc = acc_mut, comments = comments_mut;
101
+ if (!isEmpty(comments)) {
102
+ const rest = tail(comments);
103
+ const comment_1 = head_1(comments);
104
+ switch (comment_1.tag) {
105
+ case 3: {
106
+ acc_mut = {
107
+ Deprecated: append_1(acc.Deprecated, singleton(comment_1.fields[0])),
108
+ Others: acc.Others,
109
+ Remarks: acc.Remarks,
110
+ Throws: acc.Throws,
111
+ };
112
+ comments_mut = rest;
113
+ continue categorize;
114
+ }
115
+ case 8: {
116
+ acc_mut = {
117
+ Deprecated: acc.Deprecated,
118
+ Others: acc.Others,
119
+ Remarks: acc.Remarks,
120
+ Throws: append_1(acc.Throws, singleton(comment_1.fields[0])),
121
+ };
122
+ comments_mut = rest;
123
+ continue categorize;
124
+ }
125
+ case 4: {
126
+ acc_mut = {
127
+ Deprecated: acc.Deprecated,
128
+ Others: acc.Others,
129
+ Remarks: append_1(acc.Remarks, singleton(comment_1.fields[0])),
130
+ Throws: acc.Throws,
131
+ };
132
+ comments_mut = rest;
133
+ continue categorize;
134
+ }
135
+ default: {
136
+ acc_mut = {
137
+ Deprecated: acc.Deprecated,
138
+ Others: append_1(acc.Others, singleton(comment_1)),
139
+ Remarks: acc.Remarks,
140
+ Throws: acc.Throws,
141
+ };
142
+ comments_mut = rest;
143
+ continue categorize;
144
+ }
145
+ }
96
146
  }
97
147
  else {
98
- throw new Error("Should not happen");
99
- }
100
- }, patternInput[0]),
101
- Others: map((comment_1) => {
102
- switch (comment_1.tag) {
103
- case 0:
104
- return new FSharpXmlDoc(0, [comment_1.fields[0]]);
105
- case 1:
106
- return new FSharpXmlDoc(2, [comment_1.fields[0]]);
107
- case 2: {
108
- const param = comment_1.fields[0];
109
- return new FSharpXmlDoc(1, [new FSharpCommentParam(param.Name, defaultArg(map_1((content_1) => trimStart(trimStart(trimStart(content_1), "-")), param.Content), ""))]);
110
- }
111
- case 4:
112
- return new FSharpXmlDoc(3, [comment_1.fields[0]]);
113
- case 5:
114
- return new FSharpXmlDoc(4, [comment_1.fields[0]]);
115
- case 6:
116
- return new FSharpXmlDoc(5, [comment_1.fields[0]]);
117
- default:
118
- throw new Error("Should not happen");
148
+ return acc;
119
149
  }
120
- }, patternInput[1]),
150
+ break;
151
+ }
121
152
  };
153
+ const categories = categorize({
154
+ Deprecated: empty(),
155
+ Others: empty(),
156
+ Remarks: empty(),
157
+ Throws: empty(),
158
+ }, comment);
159
+ const obsoleteAttributes = map((Item) => (new FSharpAttribute(8, [Item])), categories.Deprecated);
160
+ const remarks = (!isEmpty(categories.Remarks) ? true : !isEmpty(categories.Throws)) ? (new FSharpXmlDoc(3, [join("\n", toList(delay(() => append(categories.Remarks, delay(() => append(!isEmpty(categories.Throws) ? append(!isEmpty(categories.Remarks) ? singleton_1("") : empty_1(), delay(() => append(singleton_1("Throws:"), delay(() => singleton_1("-------"))))) : empty_1(), delay(() => collect((throws) => append(singleton_1(""), delay(() => singleton_1(throws))), categories.Throws))))))))])) : void 0;
161
+ const others = map((comment_2) => {
162
+ switch (comment_2.tag) {
163
+ case 0:
164
+ return new FSharpXmlDoc(0, [comment_2.fields[0]]);
165
+ case 1:
166
+ return new FSharpXmlDoc(2, [comment_2.fields[0]]);
167
+ case 2: {
168
+ const param = comment_2.fields[0];
169
+ return new FSharpXmlDoc(1, [new FSharpCommentParam(param.Name, defaultArg(map_1((content_3) => trimStart(trimStart(trimStart(content_3), "-")), param.Content), ""))]);
170
+ }
171
+ case 5:
172
+ return new FSharpXmlDoc(4, [comment_2.fields[0]]);
173
+ case 6:
174
+ return new FSharpXmlDoc(5, [comment_2.fields[0]]);
175
+ case 7: {
176
+ const typeParam = comment_2.fields[0];
177
+ return new FSharpXmlDoc(6, [new FSharpCommentTypeParam(typeParam.TypeName, defaultArg(typeParam.Content, ""))]);
178
+ }
179
+ default:
180
+ throw new Error("Should not happen");
181
+ }
182
+ }, categories.Others);
183
+ return new TransformCommentResult(obsoleteAttributes, sortBy((xmlDoc) => {
184
+ switch (xmlDoc.tag) {
185
+ case 4:
186
+ return 1;
187
+ case 3:
188
+ return 2;
189
+ case 5:
190
+ return 3;
191
+ case 1:
192
+ return 4;
193
+ case 6:
194
+ return 5;
195
+ case 2:
196
+ return 999;
197
+ default:
198
+ return 0;
199
+ }
200
+ }, toList(delay(() => append(others, delay(() => ((remarks != null) ? singleton_1(value_4(remarks)) : empty_1()))))), {
201
+ Compare: comparePrimitives,
202
+ }));
122
203
  }
123
204
 
124
205
  function transformLiteral(glueLiteral) {
@@ -156,6 +237,8 @@ function transformPrimitive(gluePrimitive) {
156
237
  return new FSharpPrimitive(6, []);
157
238
  case 9:
158
239
  return new FSharpPrimitive(6, []);
240
+ case 10:
241
+ return new FSharpPrimitive(6, []);
159
242
  default:
160
243
  return new FSharpPrimitive(0, []);
161
244
  }
@@ -205,7 +288,14 @@ function transformType(context_mut, glueType_mut) {
205
288
  continue transformType;
206
289
  }
207
290
  else {
208
- return new FSharpType(1, [new FSharpUnion(empty(), `U${length(others)}`, map((caseType) => (new FSharpUnionCase(empty(), mapTypeNameToFableCoreAwareName(GlueType__get_Name(caseType)))), others), isOptional)]);
291
+ const matchValue = tryOptimizeUnionType(context, TransformContext__get_CurrentScopeName(context), others);
292
+ if (matchValue == null) {
293
+ return new FSharpType(1, [new FSharpUnion(empty(), `U${length(others)}`, map((caseType) => (new FSharpUnionCase(empty(), mapTypeNameToFableCoreAwareName(GlueType__get_Name(caseType)))), others), isOptional)]);
294
+ }
295
+ else {
296
+ TransformContext__ExposeType_Z1D58A540(context, matchValue);
297
+ return new FSharpType(10, [new FSharpTypeReference(TransformContext__get_FullName(context), TransformContext__get_FullName(context), empty(), new FSharpType(9, []))]);
298
+ }
209
299
  }
210
300
  }
211
301
  case 13: {
@@ -227,19 +317,36 @@ function transformType(context_mut, glueType_mut) {
227
317
  case 1:
228
318
  return new FSharpType(4, [transformInterface(context, glueType.fields[0])]);
229
319
  case 22: {
230
- const typeLiteralParameters = sortBy((_arg) => _arg.IsOptional, map((parameter_1) => {
231
- const matchValue = parameter_1.Type;
232
- if (matchValue.tag === 2) {
233
- return new FSharpParameter(parameter_1.Attributes, parameter_1.Name, true, matchValue.fields[0]);
234
- }
235
- else {
236
- return parameter_1;
320
+ const typeLiteralInfo = glueType.fields[0];
321
+ if (forAll((_arg) => {
322
+ switch (_arg.tag) {
323
+ case 4:
324
+ case 1:
325
+ case 2:
326
+ case 0:
327
+ case 5:
328
+ return true;
329
+ default:
330
+ return false;
237
331
  }
238
- }, TransformMembers_toFSharpParameters(context, glueType.fields[0].Members)), {
239
- Compare: comparePrimitives,
240
- });
241
- const explicitFields = map((parameter_2) => (new FSharpExplicitField(parameter_2.Name, parameter_2.IsOptional ? (new FSharpType(2, [parameter_2.Type])) : parameter_2.Type)), typeLiteralParameters);
242
- TransformContext__ExposeType_Z1D58A540(context, new FSharpType(16, [new FSharpClass(ofArray([new FSharpAttribute(15, []), new FSharpAttribute(7, [])]), TransformContext__get_CurrentScopeName(context), empty(), new FSharpConstructor(typeLiteralParameters, ofArray([new FSharpAttribute(16, []), new FSharpAttribute(2, [])]), new FSharpAccessibility(0, [])), empty(), explicitFields)]));
332
+ }, typeLiteralInfo.Members)) {
333
+ const typeLiteralParameters = sortBy((_arg_1) => _arg_1.IsOptional, map((parameter_1) => {
334
+ const matchValue_1 = parameter_1.Type;
335
+ if (matchValue_1.tag === 2) {
336
+ return new FSharpParameter(parameter_1.Attributes, parameter_1.Name, true, matchValue_1.fields[0]);
337
+ }
338
+ else {
339
+ return parameter_1;
340
+ }
341
+ }, TransformMembers_toFSharpParameters(context, typeLiteralInfo.Members)), {
342
+ Compare: comparePrimitives,
343
+ });
344
+ const explicitFields = map((parameter_2) => (new FSharpExplicitField(parameter_2.Name, parameter_2.IsOptional ? (new FSharpType(2, [parameter_2.Type])) : parameter_2.Type)), typeLiteralParameters);
345
+ TransformContext__ExposeType_Z1D58A540(context, new FSharpType(16, [new FSharpClass(ofArray([new FSharpAttribute(15, []), new FSharpAttribute(7, [])]), TransformContext__get_CurrentScopeName(context), empty(), new FSharpConstructor(typeLiteralParameters, ofArray([new FSharpAttribute(16, []), new FSharpAttribute(2, [])]), new FSharpAccessibility(0, [])), empty(), explicitFields)]));
346
+ }
347
+ else {
348
+ TransformContext__ExposeType_Z1D58A540(context, new FSharpType(4, [new FSharpInterface(ofArray([new FSharpAttribute(7, []), new FSharpAttribute(18, [])]), TransformContext__get_CurrentScopeName(context), "", empty(), TransformMembers_toFSharpMember(context, typeLiteralInfo.Members))]));
349
+ }
243
350
  return new FSharpType(10, [new FSharpTypeReference(TransformContext__get_FullName(context), TransformContext__get_FullName(context), empty(), new FSharpType(9, []))]);
244
351
  }
245
352
  case 25: {
@@ -253,12 +360,12 @@ function transformType(context_mut, glueType_mut) {
253
360
  continue transformType;
254
361
  }
255
362
  case 9: {
256
- const matchValue_1 = TypeAliasDeclaration_tryTransformKeyOf(TransformContext__get_CurrentScopeName(context), glueType.fields[0]);
257
- if (matchValue_1 == null) {
363
+ const matchValue_2 = TypeAliasDeclaration_tryTransformKeyOf(TransformContext__get_CurrentScopeName(context), glueType.fields[0]);
364
+ if (matchValue_2 == null) {
258
365
  return new FSharpType(17, []);
259
366
  }
260
367
  else {
261
- TransformContext__ExposeType_Z1D58A540(context, matchValue_1);
368
+ TransformContext__ExposeType_Z1D58A540(context, matchValue_2);
262
369
  return new FSharpType(10, [new FSharpTypeReference(TransformContext__get_FullName(context), TransformContext__get_FullName(context), empty(), new FSharpType(9, []))]);
263
370
  }
264
371
  }
@@ -294,23 +401,25 @@ function transformExports(context, isTopLevel, exports) {
294
401
  case 2: {
295
402
  const info = _arg.fields[0];
296
403
  const patternInput = sanitizeNameAndPushScope(info.Name, context_1);
297
- return singleton(new FSharpMember(1, [new FSharpMemberInfo(singleton(new FSharpAttribute(3, [info.Name, "REPLACE_ME_WITH_MODULE_NAME"])), patternInput[0], info.Name, empty(), empty(), transformType(patternInput[1], info.Type), false, true, void 0, new FSharpAccessibility(0, []), empty())]));
404
+ const xmlDocInfo = transformComment(info.Documentation);
405
+ return singleton(new FSharpMember(1, [new FSharpMemberInfo(toList(delay(() => append(singleton_1(new FSharpAttribute(3, [info.Name, "REPLACE_ME_WITH_MODULE_NAME"])), delay(() => xmlDocInfo.ObsoleteAttributes)))), patternInput[0], info.Name, empty(), empty(), transformType(patternInput[1], info.Type), false, true, void 0, new FSharpAccessibility(0, []), xmlDocInfo.XmlDoc)]));
298
406
  }
299
407
  case 6: {
300
408
  const info_1 = _arg.fields[0];
301
409
  const patternInput_1 = sanitizeNameAndPushScope(info_1.Name, context_1);
302
410
  const context_3 = patternInput_1[1];
303
- const xmlDocInfo = transformComment(info_1.Documentation);
304
- return singleton(new FSharpMember(0, [(Attributes_1 = toList(delay(() => append(singleton_1(new FSharpAttribute(3, [info_1.Name, "REPLACE_ME_WITH_MODULE_NAME"])), delay(() => xmlDocInfo.ObsoleteAttributes)))), (Parameters_1 = map((parameter) => transformParameter(context_3, parameter), info_1.Parameters), new FSharpMemberInfo(Attributes_1, patternInput_1[0], info_1.Name, transformTypeParameters(context_3, info_1.TypeParameters), Parameters_1, transformType(context_3, info_1.Type), false, true, void 0, new FSharpAccessibility(0, []), xmlDocInfo.Others)))]));
411
+ const xmlDocInfo_1 = transformComment(info_1.Documentation);
412
+ return singleton(new FSharpMember(0, [(Attributes_1 = toList(delay(() => append(singleton_1(new FSharpAttribute(3, [info_1.Name, "REPLACE_ME_WITH_MODULE_NAME"])), delay(() => xmlDocInfo_1.ObsoleteAttributes)))), (Parameters_1 = map((parameter) => transformParameter(context_3, parameter), info_1.Parameters), new FSharpMemberInfo(Attributes_1, patternInput_1[0], info_1.Name, transformTypeParameters(context_3, info_1.TypeParameters), Parameters_1, transformType(context_3, info_1.Type), false, true, void 0, new FSharpAccessibility(0, []), xmlDocInfo_1.XmlDoc)))]));
305
413
  }
306
414
  case 12: {
307
415
  const info_2 = _arg.fields[0];
308
416
  const patternInput_2 = sanitizeNameAndPushScope(info_2.Name, context_1);
309
417
  const context_4 = patternInput_2[1];
310
- return map((_arg_1) => {
418
+ return map((constructorInfo) => {
311
419
  let Attributes_2, Parameters_2;
312
- return new FSharpMember(0, [(Attributes_2 = toList(delay(() => (isTopLevel ? append(singleton_1(new FSharpAttribute(3, [info_2.Name, "REPLACE_ME_WITH_MODULE_NAME"])), delay(() => singleton_1(new FSharpAttribute(12, [])))) : singleton_1(new FSharpAttribute(13, [info_2.Name]))))), (Parameters_2 = map((parameter_1) => transformParameter(context_4, parameter_1), _arg_1.fields[0]), new FSharpMemberInfo(Attributes_2, patternInput_2[0], info_2.Name, transformTypeParameters(context_4, info_2.TypeParameters), Parameters_2, new FSharpType(6, [new FSharpMapped(sanitizeName(info_2.Name), empty())]), false, true, void 0, new FSharpAccessibility(0, []), empty())))]);
313
- }, isEmpty(info_2.Constructors) ? singleton(new GlueConstructor(empty())) : info_2.Constructors);
420
+ const xmlDocInfo_2 = transformComment(constructorInfo.Documentation);
421
+ return new FSharpMember(0, [(Attributes_2 = toList(delay(() => append(isTopLevel ? append(singleton_1(new FSharpAttribute(3, [info_2.Name, "REPLACE_ME_WITH_MODULE_NAME"])), delay(() => singleton_1(new FSharpAttribute(12, [])))) : singleton_1(new FSharpAttribute(13, [info_2.Name])), delay(() => xmlDocInfo_2.ObsoleteAttributes)))), (Parameters_2 = map((parameter_1) => transformParameter(context_4, parameter_1), constructorInfo.Parameters), new FSharpMemberInfo(Attributes_2, patternInput_2[0], info_2.Name, transformTypeParameters(context_4, info_2.TypeParameters), Parameters_2, new FSharpType(6, [new FSharpMapped(sanitizeName(info_2.Name), empty())]), false, true, void 0, new FSharpAccessibility(0, []), xmlDocInfo_2.XmlDoc)))]);
422
+ }, isEmpty(info_2.Constructors) ? singleton(new GlueConstructor(empty(), empty())) : info_2.Constructors);
314
423
  }
315
424
  case 11: {
316
425
  const moduleDeclaration = _arg.fields[0];
@@ -369,7 +478,10 @@ function TransformMembers_toFSharpMember(context, members) {
369
478
  return void 0;
370
479
  }
371
480
  else {
372
- return new FSharpMember(1, [new FSharpMemberInfo(toList(delay(() => xmlDocInfo.ObsoleteAttributes)), patternInput_2[0], propertyInfo.Name, empty(), empty(), transformType(patternInput_2[1], propertyInfo.Type), propertyInfo.IsOptional, propertyInfo.IsStatic, transformAccessor(propertyInfo.Accessor), propertyInfo.IsPrivate ? (new FSharpAccessibility(1, [])) : (new FSharpAccessibility(0, [])), xmlDocInfo.Others)]);
481
+ let typ;
482
+ const typ$0027 = transformType(patternInput_2[1], propertyInfo.Type);
483
+ typ = (propertyInfo.IsOptional ? ((typ$0027.tag === 2) ? typ$0027.fields[0] : typ$0027) : typ$0027);
484
+ return new FSharpMember(1, [new FSharpMemberInfo(toList(delay(() => xmlDocInfo.ObsoleteAttributes)), patternInput_2[0], propertyInfo.Name, empty(), empty(), typ, propertyInfo.IsOptional, propertyInfo.IsStatic, transformAccessor(propertyInfo.Accessor), propertyInfo.IsPrivate ? (new FSharpAccessibility(1, [])) : (new FSharpAccessibility(0, [])), xmlDocInfo.XmlDoc)]);
373
485
  }
374
486
  }
375
487
  case 3: {
@@ -382,7 +494,8 @@ function TransformMembers_toFSharpMember(context, members) {
382
494
  const methodSignature = _arg.fields[0];
383
495
  const patternInput_4 = sanitizeNameAndPushScope(methodSignature.Name, context);
384
496
  const context_5 = patternInput_4[1];
385
- return new FSharpMember(0, [new FSharpMemberInfo(empty(), patternInput_4[0], methodSignature.Name, empty(), map((parameter_4) => transformParameter(context_5, parameter_4), methodSignature.Parameters), transformType(context_5, methodSignature.Type), false, false, void 0, new FSharpAccessibility(0, []), empty())]);
497
+ const xmlDocInfo_1 = transformComment(methodSignature.Documentation);
498
+ return new FSharpMember(0, [new FSharpMemberInfo(toList(delay(() => xmlDocInfo_1.ObsoleteAttributes)), patternInput_4[0], methodSignature.Name, empty(), map((parameter_4) => transformParameter(context_5, parameter_4), methodSignature.Parameters), transformType(context_5, methodSignature.Type), false, false, void 0, new FSharpAccessibility(0, []), xmlDocInfo_1.XmlDoc)]);
386
499
  }
387
500
  case 5: {
388
501
  const constructSignature = _arg.fields[0];
@@ -555,8 +668,8 @@ export function TypeAliasDeclaration_transformKeyOf(aliasName, glueType) {
555
668
  }
556
669
  }
557
670
 
558
- export function TypeAliasDeclaration_transformLiteral(typeAliasName, literalInfo) {
559
- const makeTypeAlias = (primitiveType) => (new FSharpType(8, [new FSharpTypeAlias(typeAliasName, new FSharpType(7, [primitiveType]), empty())]));
671
+ export function TypeAliasDeclaration_transformLiteral(xmlDoc, typeAliasName, literalInfo) {
672
+ const makeTypeAlias = (primitiveType) => (new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, new FSharpType(7, [primitiveType]), empty())]));
560
673
  switch (literalInfo.tag) {
561
674
  case 1:
562
675
  return makeTypeAlias(new FSharpPrimitive(1, []));
@@ -575,62 +688,208 @@ function transformTypeParameters(context, typeParameters) {
575
688
  return map((typeParameter) => FSharpTypeParameter_Create_Z6CFD3565(typeParameter.Name, unwrap(map_1((glueType) => transformType(context, glueType), typeParameter.Constraint)), unwrap(map_1((glueType_1) => transformType(context, glueType_1), typeParameter.Default))), typeParameters);
576
689
  }
577
690
 
691
+ function tryOptimizeUnionType(context, typeName, cases) {
692
+ const flattenCases = (cases_1) => collect_1((_arg) => {
693
+ switch (_arg.tag) {
694
+ case 8:
695
+ return singleton(_arg);
696
+ case 7:
697
+ return flattenCases(_arg.fields[0].fields[0]);
698
+ case 5: {
699
+ const matchValue = _arg.fields[0].Type;
700
+ if (matchValue.tag === 7) {
701
+ return flattenCases(matchValue.fields[0].fields[0]);
702
+ }
703
+ else {
704
+ return empty();
705
+ }
706
+ }
707
+ default:
708
+ return empty();
709
+ }
710
+ }, cases_1);
711
+ const flattenedCases = flattenCases(cases);
712
+ const isStringOnly = !isEmpty(flattenedCases) && forAll((_arg_1) => {
713
+ let matchResult;
714
+ if (_arg_1.tag === 8) {
715
+ if (_arg_1.fields[0].tag === 0) {
716
+ matchResult = 0;
717
+ }
718
+ else {
719
+ matchResult = 1;
720
+ }
721
+ }
722
+ else {
723
+ matchResult = 1;
724
+ }
725
+ switch (matchResult) {
726
+ case 0:
727
+ return true;
728
+ default:
729
+ return false;
730
+ }
731
+ }, flattenedCases);
732
+ const isNumericOnly = !isEmpty(flattenedCases) && forAll((_arg_2) => {
733
+ let matchResult_1;
734
+ if (_arg_2.tag === 8) {
735
+ if (_arg_2.fields[0].tag === 1) {
736
+ matchResult_1 = 0;
737
+ }
738
+ else {
739
+ matchResult_1 = 1;
740
+ }
741
+ }
742
+ else {
743
+ matchResult_1 = 1;
744
+ }
745
+ switch (matchResult_1) {
746
+ case 0:
747
+ return true;
748
+ default:
749
+ return false;
750
+ }
751
+ }, flattenedCases);
752
+ if (isStringOnly) {
753
+ return new FSharpType(1, [new FSharpUnion(ofArray([new FSharpAttribute(11, []), new FSharpAttribute(9, [0])]), typeName, List_distinct(map((value) => {
754
+ let matchResult_2, value_1;
755
+ if (value.tag === 8) {
756
+ if (value.fields[0].tag === 0) {
757
+ matchResult_2 = 0;
758
+ value_1 = value.fields[0].fields[0];
759
+ }
760
+ else {
761
+ matchResult_2 = 1;
762
+ }
763
+ }
764
+ else {
765
+ matchResult_2 = 1;
766
+ }
767
+ switch (matchResult_2) {
768
+ case 0: {
769
+ const sanitizeResult = sanitizeNameWithResult(value_1);
770
+ return new FSharpUnionCase(toList(delay(() => (sanitizeResult.IsDifferent ? singleton_1(new FSharpAttribute(10, [removeSurroundingQuotes(value_1)])) : empty_1()))), sanitizeResult.Name);
771
+ }
772
+ default:
773
+ throw new Error("Should not happen");
774
+ }
775
+ }, flattenedCases), {
776
+ Equals: equals,
777
+ GetHashCode: safeHash,
778
+ }), false)]);
779
+ }
780
+ else if (isNumericOnly) {
781
+ return new FSharpType(0, [new FSharpEnum(typeName, List_distinct(map((value_2) => {
782
+ let matchResult_3, value_3;
783
+ if (value_2.tag === 8) {
784
+ if (value_2.fields[0].tag === 1) {
785
+ matchResult_3 = 0;
786
+ value_3 = value_2.fields[0].fields[0];
787
+ }
788
+ else {
789
+ matchResult_3 = 1;
790
+ }
791
+ }
792
+ else {
793
+ matchResult_3 = 1;
794
+ }
795
+ switch (matchResult_3) {
796
+ case 0:
797
+ return new FSharpEnumCase(int32ToString(value_3), new FSharpLiteral(1, [value_3]));
798
+ default:
799
+ throw new Error("Should not happen");
800
+ }
801
+ }, flattenedCases), {
802
+ Equals: equals,
803
+ GetHashCode: safeHash,
804
+ }))]);
805
+ }
806
+ else if (forAll((_arg_3) => {
807
+ if (_arg_3.tag === 22) {
808
+ return true;
809
+ }
810
+ else {
811
+ return false;
812
+ }
813
+ }, cases)) {
814
+ const members = collect_1((_arg_4) => {
815
+ if (_arg_4.tag === 22) {
816
+ return TransformMembers_toFSharpMember(context, _arg_4.fields[0].Members);
817
+ }
818
+ else {
819
+ return empty();
820
+ }
821
+ }, cases);
822
+ return new FSharpType(4, [new FSharpInterface(ofArray([new FSharpAttribute(7, []), new FSharpAttribute(18, [])]), typeName, TransformContext__get_CurrentScopeName(context), empty(), members)]);
823
+ }
824
+ else {
825
+ return void 0;
826
+ }
827
+ }
828
+
578
829
  function transformTypeAliasDeclaration(context, glueTypeAliasDeclaration) {
579
- let glueType_2;
580
830
  const patternInput = sanitizeNameAndPushScope(glueTypeAliasDeclaration.Name, context);
581
831
  const typeAliasName = patternInput[0];
582
832
  const context_1 = patternInput[1];
833
+ const xmlDoc = transformComment(glueTypeAliasDeclaration.Documentation);
583
834
  const matchValue = glueTypeAliasDeclaration.Type;
584
835
  switch (matchValue.tag) {
585
836
  case 9:
586
837
  return TypeAliasDeclaration_transformKeyOf(glueTypeAliasDeclaration.Name, matchValue.fields[0]);
587
838
  case 10: {
588
839
  const glueType_1 = matchValue.fields[0];
589
- return new FSharpType(8, [new FSharpTypeAlias(typeAliasName, (glueType_1.tag === 9) ? ((glueType_2 = glueType_1.fields[0], (glueType_2.tag === 1) ? transformType(context_1, new GlueType(7, [new GlueTypeUnion(List_distinct(collect_1((m) => {
590
- let typ;
591
- switch (m.tag) {
592
- case 1: {
593
- typ = m.fields[0].Type;
594
- break;
595
- }
596
- case 2: {
597
- typ = m.fields[0].Type;
598
- break;
599
- }
600
- case 5: {
601
- typ = m.fields[0].Type;
602
- break;
840
+ let typ_2;
841
+ if (glueType_1.tag === 9) {
842
+ const glueType_2 = glueType_1.fields[0];
843
+ typ_2 = ((glueType_2.tag === 1) ? transformType(context_1, new GlueType(7, [new GlueTypeUnion(List_distinct(collect_1((m) => {
844
+ let typ_1;
845
+ switch (m.tag) {
846
+ case 1: {
847
+ typ_1 = m.fields[0].Type;
848
+ break;
849
+ }
850
+ case 2: {
851
+ typ_1 = m.fields[0].Type;
852
+ break;
853
+ }
854
+ case 5: {
855
+ typ_1 = m.fields[0].Type;
856
+ break;
857
+ }
858
+ case 4: {
859
+ typ_1 = m.fields[0].Type;
860
+ break;
861
+ }
862
+ case 3: {
863
+ typ_1 = m.fields[0].Type;
864
+ break;
865
+ }
866
+ default:
867
+ typ_1 = m.fields[0].Type;
603
868
  }
604
- case 4: {
605
- typ = m.fields[0].Type;
606
- break;
869
+ if (typ_1.tag === 7) {
870
+ return typ_1.fields[0].fields[0];
607
871
  }
608
- case 3: {
609
- typ = m.fields[0].Type;
610
- break;
872
+ else {
873
+ return singleton(typ_1);
611
874
  }
612
- default:
613
- typ = m.fields[0].Type;
614
- }
615
- if (typ.tag === 7) {
616
- return typ.fields[0].fields[0];
617
- }
618
- else {
619
- return singleton(typ);
620
- }
621
- }, glueType_2.fields[0].Members), {
622
- Equals: equals,
623
- GetHashCode: safeHash,
624
- }))])) : (new FSharpType(9, [])))) : (new FSharpType(9, [])), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
875
+ }, glueType_2.fields[0].Members), {
876
+ Equals: equals,
877
+ GetHashCode: safeHash,
878
+ }))])) : (new FSharpType(9, [])));
879
+ }
880
+ else {
881
+ typ_2 = (new FSharpType(9, []));
882
+ }
883
+ return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, typ_2, transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
625
884
  }
626
885
  case 8:
627
- return TypeAliasDeclaration_transformLiteral(typeAliasName, matchValue.fields[0]);
886
+ return TypeAliasDeclaration_transformLiteral(xmlDoc, typeAliasName, matchValue.fields[0]);
628
887
  case 3:
629
- return new FSharpType(8, [new FSharpTypeAlias(typeAliasName, new FSharpType(7, [transformPrimitive(matchValue.fields[0])]), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
888
+ return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, new FSharpType(7, [transformPrimitive(matchValue.fields[0])]), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
630
889
  case 13: {
631
890
  const typeReference = matchValue.fields[0];
632
891
  const context_2 = TransformContext__PushScope_Z721C83C5(context_1, typeReference.Name);
633
- const handleDefaultCase = () => (new FSharpType(8, [new FSharpTypeAlias(typeAliasName, transformType(context_2, new GlueType(13, [typeReference])), transformTypeParameters(context_2, glueTypeAliasDeclaration.TypeParameters))]));
892
+ const handleDefaultCase = () => (new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, transformType(context_2, new GlueType(13, [typeReference])), transformTypeParameters(context_2, glueTypeAliasDeclaration.TypeParameters))]));
634
893
  const matchValue_2 = typeReference.TypeArguments;
635
894
  let matchResult_1, head;
636
895
  if (!isEmpty(matchValue_2)) {
@@ -652,7 +911,7 @@ function transformTypeAliasDeclaration(context, glueTypeAliasDeclaration) {
652
911
  const exposedType = makeInterfaceTyp("ReturnType");
653
912
  const typeArgument = makeInterfaceTyp(TransformContext__get_FullName(context_2) + ".ReturnType");
654
913
  TransformContext__ExposeType_Z1D58A540(TransformContext__PushScope_Z721C83C5(context_2, typeReference.Name), new FSharpType(4, [exposedType]));
655
- return new FSharpType(8, [new FSharpTypeAlias(typeAliasName, new FSharpType(10, [new FSharpTypeReference(typeReference.Name, typeReference.FullName, singleton(new FSharpType(4, [typeArgument])), new FSharpType(9, []))]), empty())]);
914
+ return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, new FSharpType(10, [new FSharpTypeReference(typeReference.Name, typeReference.FullName, singleton(new FSharpType(4, [typeArgument])), new FSharpType(9, []))]), empty())]);
656
915
  }
657
916
  else {
658
917
  return handleDefaultCase();
@@ -662,7 +921,7 @@ function transformTypeAliasDeclaration(context, glueTypeAliasDeclaration) {
662
921
  }
663
922
  }
664
923
  case 15:
665
- return new FSharpType(8, [new FSharpTypeAlias(typeAliasName, transformType(context_1, new GlueType(15, [matchValue.fields[0]])), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
924
+ return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, transformType(context_1, new GlueType(15, [matchValue.fields[0]])), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
666
925
  case 14: {
667
926
  const originalInterface = transformInterface(context_1, matchValue.fields[0]);
668
927
  return new FSharpType(4, [new FSharpInterface(originalInterface.Attributes, typeAliasName, originalInterface.OriginalName, originalInterface.TypeParameters, map((m_1) => {
@@ -687,19 +946,20 @@ function transformTypeAliasDeclaration(context, glueTypeAliasDeclaration) {
687
946
  return new FSharpType(4, [new FSharpInterface(ofArray([new FSharpAttribute(7, []), new FSharpAttribute(18, [])]), typeAliasName, glueTypeAliasDeclaration.Name, transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters), singleton(new FSharpMember(0, [new FSharpMemberInfo(singleton(new FSharpAttribute(1, [])), "Invoke", "Invoke", empty(), map((parameter) => transformParameter(context_1, parameter), functionType.Parameters), transformType(context_1, functionType.Type), false, false, void 0, new FSharpAccessibility(0, []), empty())])))]);
688
947
  }
689
948
  case 19:
690
- return new FSharpType(8, [new FSharpTypeAlias(typeAliasName, transformTupleType(context_1, matchValue.fields[0]), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
949
+ return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, transformTupleType(context_1, matchValue.fields[0]), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
691
950
  case 21:
692
951
  return new FSharpType(4, [new FSharpInterface(ofArray([new FSharpAttribute(7, []), new FSharpAttribute(18, [])]), typeAliasName, glueTypeAliasDeclaration.Name, transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters), TransformMembers_toFSharpMember(context_1, matchValue.fields[0]))]);
693
952
  case 22:
694
953
  return new FSharpType(4, [new FSharpInterface(ofArray([new FSharpAttribute(7, []), new FSharpAttribute(18, [])]), typeAliasName, glueTypeAliasDeclaration.Name, transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters), TransformMembers_toFSharpMember(context_1, matchValue.fields[0].Members))]);
695
954
  case 24:
696
- return new FSharpType(8, [new FSharpTypeAlias(typeAliasName, new FSharpType(17, []), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
955
+ return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, new FSharpType(17, []), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
956
+ case 17:
957
+ return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, new FSharpType(12, [matchValue.fields[0]]), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
697
958
  case 12:
698
959
  case 4:
699
960
  case 1:
700
961
  case 11:
701
962
  case 5:
702
- case 17:
703
963
  case 0:
704
964
  case 6:
705
965
  case 18:
@@ -709,122 +969,12 @@ function transformTypeAliasDeclaration(context, glueTypeAliasDeclaration) {
709
969
  case 23:
710
970
  return new FSharpType(9, []);
711
971
  default: {
712
- const flattenCases = (cases_1) => collect_1((_arg) => {
713
- switch (_arg.tag) {
714
- case 8:
715
- return singleton(_arg);
716
- case 7:
717
- return flattenCases(_arg.fields[0].fields[0]);
718
- case 5: {
719
- const matchValue_1 = _arg.fields[0].Type;
720
- if (matchValue_1.tag === 7) {
721
- return flattenCases(matchValue_1.fields[0].fields[0]);
722
- }
723
- else {
724
- return empty();
725
- }
726
- }
727
- default:
728
- return empty();
729
- }
730
- }, cases_1);
731
- const flattenedCases = flattenCases(matchValue.fields[0].fields[0]);
732
- const isStringOnly = !isEmpty(flattenedCases) && forAll((_arg_1) => {
733
- let matchResult_2;
734
- if (_arg_1.tag === 8) {
735
- if (_arg_1.fields[0].tag === 0) {
736
- matchResult_2 = 0;
737
- }
738
- else {
739
- matchResult_2 = 1;
740
- }
741
- }
742
- else {
743
- matchResult_2 = 1;
744
- }
745
- switch (matchResult_2) {
746
- case 0:
747
- return true;
748
- default:
749
- return false;
750
- }
751
- }, flattenedCases);
752
- const isNumericOnly = !isEmpty(flattenedCases) && forAll((_arg_2) => {
753
- let matchResult_3;
754
- if (_arg_2.tag === 8) {
755
- if (_arg_2.fields[0].tag === 1) {
756
- matchResult_3 = 0;
757
- }
758
- else {
759
- matchResult_3 = 1;
760
- }
761
- }
762
- else {
763
- matchResult_3 = 1;
764
- }
765
- switch (matchResult_3) {
766
- case 0:
767
- return true;
768
- default:
769
- return false;
770
- }
771
- }, flattenedCases);
772
- if (isStringOnly) {
773
- return new FSharpType(1, [new FSharpUnion(ofArray([new FSharpAttribute(11, []), new FSharpAttribute(9, [0])]), typeAliasName, List_distinct(map((value) => {
774
- let matchResult_4, value_1;
775
- if (value.tag === 8) {
776
- if (value.fields[0].tag === 0) {
777
- matchResult_4 = 0;
778
- value_1 = value.fields[0].fields[0];
779
- }
780
- else {
781
- matchResult_4 = 1;
782
- }
783
- }
784
- else {
785
- matchResult_4 = 1;
786
- }
787
- switch (matchResult_4) {
788
- case 0: {
789
- const sanitizeResult = sanitizeNameWithResult(value_1);
790
- return new FSharpUnionCase(toList(delay(() => (sanitizeResult.IsDifferent ? singleton_1(new FSharpAttribute(10, [removeSurroundingQuotes(value_1)])) : empty_1()))), sanitizeResult.Name);
791
- }
792
- default:
793
- throw new Error("Should not happen");
794
- }
795
- }, flattenedCases), {
796
- Equals: equals,
797
- GetHashCode: safeHash,
798
- }), false)]);
799
- }
800
- else if (isNumericOnly) {
801
- return new FSharpType(0, [new FSharpEnum(typeAliasName, List_distinct(map((value_2) => {
802
- let matchResult_5, value_3;
803
- if (value_2.tag === 8) {
804
- if (value_2.fields[0].tag === 1) {
805
- matchResult_5 = 0;
806
- value_3 = value_2.fields[0].fields[0];
807
- }
808
- else {
809
- matchResult_5 = 1;
810
- }
811
- }
812
- else {
813
- matchResult_5 = 1;
814
- }
815
- switch (matchResult_5) {
816
- case 0:
817
- return new FSharpEnumCase(int32ToString(value_3), new FSharpLiteral(1, [value_3]));
818
- default:
819
- throw new Error("Should not happen");
820
- }
821
- }, flattenedCases), {
822
- Equals: equals,
823
- GetHashCode: safeHash,
824
- }))]);
972
+ const matchValue_1 = tryOptimizeUnionType(context_1, typeAliasName, matchValue.fields[0].fields[0]);
973
+ if (matchValue_1 == null) {
974
+ return new FSharpType(8, [new FSharpTypeAlias(toList(delay(() => xmlDoc.ObsoleteAttributes)), typeAliasName, xmlDoc.XmlDoc, transformType(context_1, matchValue), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
825
975
  }
826
976
  else {
827
- return new FSharpType(8, [new FSharpTypeAlias(typeAliasName, transformType(context_1, matchValue), transformTypeParameters(context_1, glueTypeAliasDeclaration.TypeParameters))]);
977
+ return matchValue_1;
828
978
  }
829
979
  }
830
980
  }