@glutinum/cli 1.0.0-beta.1 → 1.0.0-beta.11

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.
Files changed (155) hide show
  1. package/README.md +16 -0
  2. package/dist/Glutinum.Converter/Abbreviations.js +16 -39
  3. package/dist/Glutinum.Converter/DelegateExtensions.js +378 -0
  4. package/dist/Glutinum.Converter/FreeTypeParameters.js +211 -0
  5. package/dist/Glutinum.Converter/FsharpAST.js +117 -66
  6. package/dist/Glutinum.Converter/Generate.js +52 -26
  7. package/dist/Glutinum.Converter/GlueAST.js +85 -46
  8. package/dist/Glutinum.Converter/Hosting.js +148 -174
  9. package/dist/Glutinum.Converter/Merge.js +463 -355
  10. package/dist/Glutinum.Converter/Packages.js +387 -97
  11. package/dist/Glutinum.Converter/Printer.js +439 -400
  12. package/dist/Glutinum.Converter/Read.js +362 -100
  13. package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +7 -7
  14. package/dist/Glutinum.Converter/Reader/ConditionalTypeNode.js +90 -0
  15. package/dist/Glutinum.Converter/Reader/Declaration.js +13 -19
  16. package/dist/Glutinum.Converter/Reader/Deferred.js +706 -0
  17. package/dist/Glutinum.Converter/Reader/Documentation.js +28 -40
  18. package/dist/Glutinum.Converter/Reader/EnumDeclaration.js +2 -2
  19. package/dist/Glutinum.Converter/Reader/ExportAssignment.js +104 -37
  20. package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +24 -39
  21. package/dist/Glutinum.Converter/Reader/ExpressionWithTypeArguments.js +59 -0
  22. package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +30 -17
  23. package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +16 -22
  24. package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +49 -6
  25. package/dist/Glutinum.Converter/Reader/IntersectionTypeNode.js +178 -0
  26. package/dist/Glutinum.Converter/Reader/MappedTypeNode.js +4 -4
  27. package/dist/Glutinum.Converter/Reader/MemberTypes.js +126 -0
  28. package/dist/Glutinum.Converter/Reader/ModuleDeclaration.js +54 -6
  29. package/dist/Glutinum.Converter/Reader/Node.js +11 -14
  30. package/dist/Glutinum.Converter/Reader/Parameters.js +39 -30
  31. package/dist/Glutinum.Converter/Reader/Report.js +4 -4
  32. package/dist/Glutinum.Converter/Reader/TypeNode.js +390 -1584
  33. package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +80 -53
  34. package/dist/Glutinum.Converter/Reader/TypeParameters.js +2 -2
  35. package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +24 -47
  36. package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +24 -6
  37. package/dist/Glutinum.Converter/Reader/Types.js +297 -17
  38. package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +16 -30
  39. package/dist/Glutinum.Converter/Reader/UtilityType.js +811 -0
  40. package/dist/Glutinum.Converter/Reader/Utils.js +497 -111
  41. package/dist/Glutinum.Converter/Reader/VariableStatement.js +7 -8
  42. package/dist/Glutinum.Converter/Transform.js +2915 -8180
  43. package/dist/Glutinum.Converter/Transformer/AnyFunctionOverloads.js +116 -0
  44. package/dist/Glutinum.Converter/Transformer/CallableProperties.js +454 -0
  45. package/dist/Glutinum.Converter/Transformer/Comment.js +136 -0
  46. package/dist/Glutinum.Converter/Transformer/Conditionals.js +1087 -0
  47. package/dist/Glutinum.Converter/Transformer/Context.js +678 -0
  48. package/dist/Glutinum.Converter/Transformer/Enum.js +80 -0
  49. package/dist/Glutinum.Converter/Transformer/Exports.js +704 -0
  50. package/dist/Glutinum.Converter/Transformer/Heritage.js +493 -0
  51. package/dist/Glutinum.Converter/Transformer/KeyOfMaps.js +488 -0
  52. package/dist/Glutinum.Converter/Transformer/ParamObjectCandidate.js +460 -0
  53. package/dist/Glutinum.Converter/Transformer/TypeParameter.js +219 -0
  54. package/dist/Glutinum.Converter/Transformer/TypeParameters.js +448 -0
  55. package/dist/Glutinum.Converter/Transformer/UnionOverloads.js +338 -0
  56. package/dist/Glutinum.Converter/Transformer/Utils.js +341 -0
  57. package/dist/Glutinum.Converter/TypeScript.Extensions.js +0 -10
  58. package/dist/Glutinum.Converter/Utils/Keywords.js +3 -3
  59. package/dist/Glutinum.Converter/Utils/List.js +2 -2
  60. package/dist/Glutinum.Converter/Utils/Naming.js +6 -6
  61. package/dist/Glutinum.Converter/Utils/String.js +16 -5
  62. package/dist/Program.js +104 -241
  63. package/dist/fable_modules/Fable.Promise.3.2.1/AsyncIterable.fs.js +2 -2
  64. package/dist/fable_modules/Fable.Promise.3.2.1/Promise.fs.js +4 -4
  65. package/dist/fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs.js +2 -2
  66. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Array.fs.js +5 -5
  67. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Async.fs.js +4 -4
  68. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionCE.fs.js +3 -3
  69. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultCE.fs.js +1 -1
  70. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOption.fs.js +3 -3
  71. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionCE.fs.js +1 -1
  72. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationCE.fs.js +1 -1
  73. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/List.fs.js +4 -4
  74. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionCE.fs.js +1 -1
  75. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResult.fs.js +3 -3
  76. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResultCE.fs.js +1 -1
  77. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidationCE.fs.js +1 -1
  78. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Result.fs.js +1 -1
  79. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultCE.fs.js +2 -2
  80. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOption.fs.js +2 -2
  81. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionCE.fs.js +1 -1
  82. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Seq.fs.js +7 -7
  83. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationCE.fs.js +1 -1
  84. package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Async.js +21 -7
  85. package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/AsyncBuilder.js +51 -6
  86. package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/CHANGELOG.md +23 -1
  87. package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/CollectionUtil.js +10 -16
  88. package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/MailboxProcessor.js +19 -3
  89. package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/MutableMap.js +5 -1
  90. package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/MutableSet.js +5 -1
  91. package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Util.js +15 -3
  92. package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/package.json +1 -1
  93. package/package.json +3 -2
  94. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Array.js +0 -0
  95. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/BigInt.js +0 -0
  96. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/BitConverter.js +0 -0
  97. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Boolean.js +0 -0
  98. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Char.js +0 -0
  99. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Choice.js +0 -0
  100. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/ConditionalWeakTable.js +0 -0
  101. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Date.js +0 -0
  102. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/DateOffset.js +0 -0
  103. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/DateOnly.js +0 -0
  104. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/DateOnlyTemporal.js +0 -0
  105. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/DateTimeFormat.js +0 -0
  106. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/DateTimeOffsetTemporal.js +0 -0
  107. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/DateTimeTemporal.js +0 -0
  108. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Decimal.js +0 -0
  109. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Directory.js +0 -0
  110. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Double.js +0 -0
  111. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Encoding.js +0 -0
  112. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Environment.js +0 -0
  113. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Event.js +0 -0
  114. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/FSharp.Collections.js +0 -0
  115. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/FSharp.Core.CompilerServices.js +0 -0
  116. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/FSharp.Core.js +0 -0
  117. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/File.js +0 -0
  118. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Global.js +0 -0
  119. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Guid.js +0 -0
  120. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Int32.js +0 -0
  121. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/List.js +0 -0
  122. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Long.js +0 -0
  123. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Map.js +0 -0
  124. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/MapUtil.js +0 -0
  125. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Native.js +0 -0
  126. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Numeric.js +0 -0
  127. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Observable.js +0 -0
  128. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Option.js +0 -0
  129. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Path.js +0 -0
  130. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/README.md +0 -0
  131. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Random.js +0 -0
  132. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Range.js +0 -0
  133. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Reflection.js +0 -0
  134. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/RegExp.js +0 -0
  135. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Result.js +0 -0
  136. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Seq.js +0 -0
  137. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Seq2.js +0 -0
  138. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Set.js +0 -0
  139. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/String.js +0 -0
  140. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/System.Collections.Generic.js +0 -0
  141. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/System.Text.js +0 -0
  142. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/System.js +0 -0
  143. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Task.js +0 -0
  144. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/TaskBuilder.js +0 -0
  145. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/TimeOnly.js +0 -0
  146. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/TimeOnlyTemporal.js +0 -0
  147. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/TimeSpan.js +0 -0
  148. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/TimeSpanTemporal.js +0 -0
  149. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Timer.js +0 -0
  150. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Types.js +0 -0
  151. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Unicode.13.0.0.js +0 -0
  152. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/Uri.js +0 -0
  153. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/big.d.ts +0 -0
  154. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/lib/big.js +0 -0
  155. /package/dist/fable_modules/{fable-library-js.5.17.2 → fable-library-js.5.21.0}/quotation.js +0 -0
@@ -0,0 +1,1087 @@
1
+
2
+ import { Union, Record } from "../../fable_modules/fable-library-js.5.21.0/Types.js";
3
+ import { GlueFunctionDeclaration, GlueProperty, GlueMethodSignature, GlueMember, GlueMethod, GlueTypeParameter, GlueParameter_$reflection, GlueTypeParameter_$reflection, GlueFunctionType, GlueParameter, GlueTypeUnion, GlueTypeReference, GlueSubstitution_mentionedTypeParameters, GlueConditionalType, GlueSubstitution_substitute, GlueType, GluePrimitive, GlueClassDeclaration_$reflection, GlueInterface_$reflection, GlueTypeAliasDeclaration_$reflection, GlueType_$reflection } from "../GlueAST.js";
4
+ import { union_type, record_type, class_type, string_type, list_type } from "../../fable_modules/fable-library-js.5.21.0/Reflection.js";
5
+ import { collect as collect_1, append, empty as empty_1, choose, singleton, cons, tryPick, zip, length, head as head_2, tail, item, mapIndexed, ofArray, filter, contains, forAll, isEmpty, map as map_1, exists, iterate } from "../../fable_modules/fable-library-js.5.21.0/List.js";
6
+ import { ofSeq as ofSeq_1, add, empty, FSharpSet__Contains, FSharpSet__Add } from "../../fable_modules/fable-library-js.5.21.0/Set.js";
7
+ import { getItemFromDict } from "../../fable_modules/fable-library-js.5.21.0/MapUtil.js";
8
+ import { safeHash, stringHash, equals, comparePrimitives, disposeSafe, getEnumerator, curry2 } from "../../fable_modules/fable-library-js.5.21.0/Util.js";
9
+ import { empty as empty_2, FSharpMap__get_IsEmpty, FSharpMap__get_Item, FSharpMap__TryFind, ofList, FSharpMap__ContainsKey, ofSeq } from "../../fable_modules/fable-library-js.5.21.0/Map.js";
10
+ import { map } from "../../fable_modules/fable-library-js.5.21.0/Seq.js";
11
+ import { defaultArg } from "../../fable_modules/fable-library-js.5.21.0/Option.js";
12
+ import { List_distinct } from "../../fable_modules/fable-library-js.5.21.0/Seq2.js";
13
+
14
+ /**
15
+ * The declarations of the run by their full name, built once by `create`
16
+ */
17
+ export class State extends Record {
18
+ constructor(TypeMemory, AllAliases, Interfaces, Aliases, Classes) {
19
+ super();
20
+ this.TypeMemory = TypeMemory;
21
+ this.AllAliases = AllAliases;
22
+ this.Interfaces = Interfaces;
23
+ this.Aliases = Aliases;
24
+ this.Classes = Classes;
25
+ }
26
+ }
27
+
28
+ export function State_$reflection() {
29
+ return record_type("Glutinum.Converter.Transformer.Conditionals.State", [], State, () => [["TypeMemory", list_type(GlueType_$reflection())], ["AllAliases", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, GlueTypeAliasDeclaration_$reflection()])], ["Interfaces", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, GlueInterface_$reflection()])], ["Aliases", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, GlueTypeAliasDeclaration_$reflection()])], ["Classes", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, GlueClassDeclaration_$reflection()])]]);
30
+ }
31
+
32
+ export function create(typeMemory) {
33
+ const allAliases = new Map([]);
34
+ const interfaces = new Map([]);
35
+ const aliases = new Map([]);
36
+ const classes = new Map([]);
37
+ const collect = (glueType) => {
38
+ switch (glueType.tag) {
39
+ case 5: {
40
+ const info = glueType.fields[0];
41
+ allAliases.set(info.FullName, info);
42
+ break;
43
+ }
44
+ case 1: {
45
+ const info_1 = glueType.fields[0];
46
+ interfaces.set(info_1.FullName, info_1);
47
+ break;
48
+ }
49
+ case 12: {
50
+ const info_2 = glueType.fields[0];
51
+ classes.set(info_2.FullName, info_2);
52
+ break;
53
+ }
54
+ case 11: {
55
+ iterate(collect, glueType.fields[0].Types);
56
+ break;
57
+ }
58
+ case 31: {
59
+ iterate(collect, glueType.fields[0].Types);
60
+ break;
61
+ }
62
+ default:
63
+ undefined;
64
+ }
65
+ };
66
+ const isConditional = (visited_mut, glueType_1_mut) => {
67
+ isConditional:
68
+ while (true) {
69
+ const visited = visited_mut, glueType_1 = glueType_1_mut;
70
+ let typeReference;
71
+ let matchResult, typeReference_1, typeReference_2, innerType, elements;
72
+ switch (glueType_1.tag) {
73
+ case 33: {
74
+ matchResult = 0;
75
+ break;
76
+ }
77
+ case 13: {
78
+ if ((typeReference = glueType_1.fields[0], allAliases.has(typeReference.FullName) && !FSharpSet__Contains(visited, typeReference.FullName))) {
79
+ matchResult = 1;
80
+ typeReference_1 = glueType_1.fields[0];
81
+ }
82
+ else {
83
+ matchResult = 2;
84
+ typeReference_2 = glueType_1.fields[0];
85
+ }
86
+ break;
87
+ }
88
+ case 14: {
89
+ matchResult = 3;
90
+ innerType = glueType_1.fields[0];
91
+ break;
92
+ }
93
+ case 30: {
94
+ matchResult = 3;
95
+ innerType = glueType_1.fields[0];
96
+ break;
97
+ }
98
+ case 23: {
99
+ matchResult = 3;
100
+ innerType = glueType_1.fields[0];
101
+ break;
102
+ }
103
+ case 18: {
104
+ matchResult = 4;
105
+ elements = glueType_1.fields[0];
106
+ break;
107
+ }
108
+ default:
109
+ matchResult = 5;
110
+ }
111
+ switch (matchResult) {
112
+ case 0:
113
+ return true;
114
+ case 1:
115
+ if (isConditional(FSharpSet__Add(visited, typeReference_1.FullName), getItemFromDict(allAliases, typeReference_1.FullName).Type)) {
116
+ return true;
117
+ }
118
+ else {
119
+ return exists(curry2(isConditional)(visited), typeReference_1.TypeArguments);
120
+ }
121
+ case 2:
122
+ return exists(curry2(isConditional)(visited), typeReference_2.TypeArguments);
123
+ case 3: {
124
+ visited_mut = visited;
125
+ glueType_1_mut = innerType;
126
+ continue isConditional;
127
+ }
128
+ case 4:
129
+ return exists(curry2(isConditional)(visited), elements);
130
+ default:
131
+ return false;
132
+ }
133
+ break;
134
+ }
135
+ };
136
+ iterate(collect, typeMemory);
137
+ let enumerator = getEnumerator(allAliases);
138
+ try {
139
+ while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
140
+ const activePatternResult = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
141
+ const alias = activePatternResult[1];
142
+ if (isConditional(empty({
143
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
144
+ }), alias.Type)) {
145
+ aliases.set(activePatternResult[0], alias);
146
+ }
147
+ }
148
+ }
149
+ finally {
150
+ disposeSafe(enumerator);
151
+ }
152
+ const toMap = (dictionary) => ofSeq(map((_arg) => {
153
+ const activePatternResult_1 = _arg;
154
+ return [activePatternResult_1[0], activePatternResult_1[1]];
155
+ }, dictionary), {
156
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
157
+ });
158
+ return new State(typeMemory, toMap(allAliases), toMap(interfaces), toMap(aliases), toMap(classes));
159
+ }
160
+
161
+ export function isConditionalAlias(state, fullName) {
162
+ return FSharpMap__ContainsKey(state.Aliases, fullName);
163
+ }
164
+
165
+ function withInferredConstraints(conditionalType) {
166
+ const constraints = ofList(map_1((typeParameter) => [typeParameter.Name, defaultArg(typeParameter.Constraint, new GlueType(/* Primitive */ 3, [GluePrimitive.Any]))], conditionalType.Inferred), {
167
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
168
+ });
169
+ return new GlueConditionalType(conditionalType.CheckType, GlueSubstitution_substitute(constraints, conditionalType.ExtendsType), GlueSubstitution_substitute(constraints, conditionalType.TrueType), conditionalType.FalseType, conditionalType.Inferred);
170
+ }
171
+
172
+ function isErrorClass(state, visited, fullName) {
173
+ const matchValue = FSharpMap__TryFind(state.Classes, fullName);
174
+ if (matchValue != null) {
175
+ return exists((_arg) => {
176
+ if (_arg.tag === 13) {
177
+ const typeReference = _arg.fields[0];
178
+ if (typeReference.IsStandardLibrary && (typeReference.Name === "Error")) {
179
+ return true;
180
+ }
181
+ else if (!FSharpSet__Contains(visited, typeReference.FullName)) {
182
+ return isErrorClass(state, FSharpSet__Add(visited, fullName), typeReference.FullName);
183
+ }
184
+ else {
185
+ return false;
186
+ }
187
+ }
188
+ else {
189
+ return false;
190
+ }
191
+ }, matchValue.HeritageClauses);
192
+ }
193
+ else {
194
+ return false;
195
+ }
196
+ }
197
+
198
+ /**
199
+ * Whether the declaration behind a reference is printed as an F# interface
200
+ */
201
+ export function isInterfaceDeclaration(state, fullName) {
202
+ if (FSharpMap__ContainsKey(state.Interfaces, fullName)) {
203
+ return true;
204
+ }
205
+ else if (FSharpMap__ContainsKey(state.Classes, fullName)) {
206
+ return !isErrorClass(state, empty({
207
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
208
+ }), fullName);
209
+ }
210
+ else if (FSharpMap__ContainsKey(state.AllAliases, fullName)) {
211
+ const matchValue = FSharpMap__get_Item(state.AllAliases, fullName).Type;
212
+ switch (matchValue.tag) {
213
+ case 20:
214
+ return !isEmpty(matchValue.fields[0]);
215
+ case 22:
216
+ return !isEmpty(matchValue.fields[0].Members);
217
+ default:
218
+ return false;
219
+ }
220
+ }
221
+ else {
222
+ return false;
223
+ }
224
+ }
225
+
226
+ function tryCollapse(resolve_1, conditionalType) {
227
+ let head;
228
+ const trueType = equals(conditionalType.TrueType, conditionalType.CheckType) ? conditionalType.ExtendsType : conditionalType.TrueType;
229
+ const checkedNames = GlueSubstitution_mentionedTypeParameters(conditionalType.CheckType);
230
+ const withoutCheckedTypeParameters = (glueType) => {
231
+ if (forAll((name) => !contains(name, checkedNames, {
232
+ Equals: (x, y) => (x === y),
233
+ GetHashCode: (x) => (stringHash(x) | 0),
234
+ }), GlueSubstitution_mentionedTypeParameters(glueType))) {
235
+ return glueType;
236
+ }
237
+ else {
238
+ return undefined;
239
+ }
240
+ };
241
+ const matchValue = List_distinct(filter((y_1) => !equals(new GlueType(/* Primitive */ 3, [GluePrimitive.Never]), y_1), map_1(resolve_1, ofArray([trueType, conditionalType.FalseType]))), {
242
+ Equals: equals,
243
+ GetHashCode: (x_2) => (safeHash(x_2) | 0),
244
+ });
245
+ let matchResult, single, branches_1, head_1;
246
+ if (!isEmpty(matchValue)) {
247
+ if (isEmpty(tail(matchValue))) {
248
+ matchResult = 0;
249
+ single = head_2(matchValue);
250
+ }
251
+ else if (head_2(matchValue).tag === 13) {
252
+ if ((head = head_2(matchValue).fields[0], forAll((_arg) => {
253
+ if (_arg.tag === 13) {
254
+ const other = _arg.fields[0];
255
+ if (other.FullName === head.FullName) {
256
+ return length(other.TypeArguments) === length(head.TypeArguments);
257
+ }
258
+ else {
259
+ return false;
260
+ }
261
+ }
262
+ else {
263
+ return false;
264
+ }
265
+ }, matchValue))) {
266
+ matchResult = 1;
267
+ branches_1 = matchValue;
268
+ head_1 = head_2(matchValue).fields[0];
269
+ }
270
+ else {
271
+ matchResult = 2;
272
+ }
273
+ }
274
+ else {
275
+ matchResult = 2;
276
+ }
277
+ }
278
+ else {
279
+ matchResult = 2;
280
+ }
281
+ switch (matchResult) {
282
+ case 0:
283
+ return withoutCheckedTypeParameters(single);
284
+ case 1:
285
+ return withoutCheckedTypeParameters(new GlueType(/* TypeReference */ 13, [new GlueTypeReference(head_1.Name, head_1.FullName, head_1.ModulePath, mapIndexed((index, argument) => {
286
+ if (forAll((_arg_1) => {
287
+ if (_arg_1.tag === 13) {
288
+ return equals(item(index, _arg_1.fields[0].TypeArguments), argument);
289
+ }
290
+ else {
291
+ return false;
292
+ }
293
+ }, branches_1)) {
294
+ return argument;
295
+ }
296
+ else {
297
+ return new GlueType(/* Primitive */ 3, [GluePrimitive.Any]);
298
+ }
299
+ }, head_1.TypeArguments), head_1.IsStandardLibrary)]));
300
+ default:
301
+ return undefined;
302
+ }
303
+ }
304
+
305
+ function mentionsConditional(state_mut, glueType_mut) {
306
+ mentionsConditional:
307
+ while (true) {
308
+ const state = state_mut, glueType = glueType_mut;
309
+ let matchResult, innerType;
310
+ switch (glueType.tag) {
311
+ case 33: {
312
+ matchResult = 0;
313
+ break;
314
+ }
315
+ case 13: {
316
+ matchResult = 1;
317
+ break;
318
+ }
319
+ case 7: {
320
+ matchResult = 2;
321
+ break;
322
+ }
323
+ case 14: {
324
+ matchResult = 3;
325
+ innerType = glueType.fields[0];
326
+ break;
327
+ }
328
+ case 30: {
329
+ matchResult = 3;
330
+ innerType = glueType.fields[0];
331
+ break;
332
+ }
333
+ case 23: {
334
+ matchResult = 3;
335
+ innerType = glueType.fields[0];
336
+ break;
337
+ }
338
+ case 18: {
339
+ matchResult = 4;
340
+ break;
341
+ }
342
+ case 10: {
343
+ matchResult = 5;
344
+ break;
345
+ }
346
+ default:
347
+ matchResult = 6;
348
+ }
349
+ switch (matchResult) {
350
+ case 0:
351
+ return true;
352
+ case 1: {
353
+ const typeReference = glueType.fields[0];
354
+ if (FSharpMap__ContainsKey(state.Aliases, typeReference.FullName)) {
355
+ return true;
356
+ }
357
+ else {
358
+ return exists((glueType_1) => mentionsConditional(state, glueType_1), typeReference.TypeArguments);
359
+ }
360
+ }
361
+ case 2:
362
+ return exists((glueType_2) => mentionsConditional(state, glueType_2), glueType.fields[0].fields[0]);
363
+ case 3: {
364
+ state_mut = state;
365
+ glueType_mut = innerType;
366
+ continue mentionsConditional;
367
+ }
368
+ case 4:
369
+ return exists((glueType_3) => mentionsConditional(state, glueType_3), glueType.fields[0]);
370
+ case 5: {
371
+ const indexedAccess = glueType.fields[0];
372
+ if (mentionsConditional(state, indexedAccess.ObjectType)) {
373
+ return true;
374
+ }
375
+ else {
376
+ state_mut = state;
377
+ glueType_mut = indexedAccess.IndexType;
378
+ continue mentionsConditional;
379
+ }
380
+ }
381
+ default:
382
+ return false;
383
+ }
384
+ break;
385
+ }
386
+ }
387
+
388
+ function resolveWith(state, seen, glueType) {
389
+ let typeReference, Parameters;
390
+ const resolve_1 = (glueType_1) => resolveWith(state, seen, glueType_1);
391
+ switch (glueType.tag) {
392
+ case 13:
393
+ if ((typeReference = glueType.fields[0], (FSharpMap__ContainsKey(state.Aliases, typeReference.FullName) && (length(FSharpMap__get_Item(state.Aliases, typeReference.FullName).TypeParameters) === length(typeReference.TypeArguments))) && !FSharpSet__Contains(seen, typeReference.FullName))) {
394
+ const alias = FSharpMap__get_Item(state.Aliases, glueType.fields[0].FullName);
395
+ let resolve_2;
396
+ const seen_1 = add(glueType.fields[0].FullName, seen);
397
+ resolve_2 = ((glueType_2) => resolveWith(state, seen_1, glueType_2));
398
+ const matchValue = GlueSubstitution_substitute(ofList(zip(map_1((_arg) => _arg.Name, alias.TypeParameters), glueType.fields[0].TypeArguments), {
399
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
400
+ }), alias.Type);
401
+ switch (matchValue.tag) {
402
+ case 33:
403
+ return defaultArg(tryCollapse(resolve_2, withInferredConstraints(matchValue.fields[0])), glueType);
404
+ case 13: {
405
+ const matchValue_1 = resolve_2(matchValue);
406
+ let matchResult, resolved_1, resolved_2;
407
+ if (matchValue_1.tag === 13) {
408
+ if (FSharpMap__ContainsKey(state.Aliases, matchValue_1.fields[0].FullName)) {
409
+ matchResult = 0;
410
+ resolved_1 = matchValue_1.fields[0];
411
+ }
412
+ else {
413
+ matchResult = 1;
414
+ resolved_2 = matchValue_1;
415
+ }
416
+ }
417
+ else {
418
+ matchResult = 1;
419
+ resolved_2 = matchValue_1;
420
+ }
421
+ switch (matchResult) {
422
+ case 0:
423
+ return glueType;
424
+ default:
425
+ return resolved_2;
426
+ }
427
+ }
428
+ default: {
429
+ const resolved_3 = resolve_2(matchValue);
430
+ if (mentionsConditional(state, resolved_3)) {
431
+ return glueType;
432
+ }
433
+ else {
434
+ return resolved_3;
435
+ }
436
+ }
437
+ }
438
+ }
439
+ else {
440
+ return new GlueType(/* TypeReference */ 13, [new GlueTypeReference(glueType.fields[0].Name, glueType.fields[0].FullName, glueType.fields[0].ModulePath, map_1(resolve_1, glueType.fields[0].TypeArguments), glueType.fields[0].IsStandardLibrary)]);
441
+ }
442
+ case 33:
443
+ return defaultArg(tryCollapse(resolve_1, withInferredConstraints(glueType.fields[0])), glueType);
444
+ case 7:
445
+ return new GlueType(/* Union */ 7, [new GlueTypeUnion(map_1(resolve_1, glueType.fields[0].fields[0]))]);
446
+ case 14:
447
+ return new GlueType(/* Array */ 14, [resolve_1(glueType.fields[0])]);
448
+ case 30:
449
+ return new GlueType(/* ReadOnly */ 30, [resolve_1(glueType.fields[0])]);
450
+ case 23:
451
+ return new GlueType(/* OptionalType */ 23, [resolve_1(glueType.fields[0])]);
452
+ case 18:
453
+ return new GlueType(/* TupleType */ 18, [map_1(resolve_1, glueType.fields[0])]);
454
+ case 15:
455
+ return new GlueType(/* FunctionType */ 15, [(Parameters = map_1((parameter) => (new GlueParameter(parameter.Name, parameter.IsOptional, parameter.IsSpread, resolve_1(parameter.Type))), glueType.fields[0].Parameters), new GlueFunctionType(glueType.fields[0].Documentation, resolve_1(glueType.fields[0].Type), glueType.fields[0].TypeParameters, glueType.fields[0].OwnTypeParameterNames, Parameters))]);
456
+ default:
457
+ return glueType;
458
+ }
459
+ }
460
+
461
+ function resolve(state, glueType) {
462
+ if (FSharpMap__get_IsEmpty(state.Aliases)) {
463
+ return glueType;
464
+ }
465
+ else {
466
+ return resolveWith(state, empty({
467
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
468
+ }), glueType);
469
+ }
470
+ }
471
+
472
+ class Branch extends Union {
473
+ constructor(tag, fields) {
474
+ super();
475
+ this.tag = tag;
476
+ this.fields = fields;
477
+ }
478
+ cases() {
479
+ return ["Overload", "Nothing", "Inexpressible"];
480
+ }
481
+ static Nothing = new Branch(1, []);
482
+ static Inexpressible = new Branch(2, []);
483
+ }
484
+
485
+ function Branch_$reflection() {
486
+ return union_type("Glutinum.Converter.Transformer.Conditionals.Branch", [], Branch, () => [[["extends", GlueType_$reflection()], ["result", GlueType_$reflection()], ["inferred", list_type(GlueTypeParameter_$reflection())]], [], []]);
487
+ }
488
+
489
+ function expandAlias(state, typeReference) {
490
+ const matchValue = FSharpMap__TryFind(state.AllAliases, typeReference.FullName);
491
+ let matchResult, alias_1;
492
+ if (matchValue != null) {
493
+ if (length(matchValue.TypeParameters) === length(typeReference.TypeArguments)) {
494
+ matchResult = 0;
495
+ alias_1 = matchValue;
496
+ }
497
+ else {
498
+ matchResult = 1;
499
+ }
500
+ }
501
+ else {
502
+ matchResult = 1;
503
+ }
504
+ switch (matchResult) {
505
+ case 0:
506
+ return GlueSubstitution_substitute(ofList(zip(map_1((_arg) => _arg.Name, alias_1.TypeParameters), typeReference.TypeArguments), {
507
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
508
+ }), alias_1.Type);
509
+ default:
510
+ return undefined;
511
+ }
512
+ }
513
+
514
+ function inlineConditional(state, glueType) {
515
+ switch (glueType.tag) {
516
+ case 33:
517
+ return glueType.fields[0];
518
+ case 13: {
519
+ const matchValue = expandAlias(state, glueType.fields[0]);
520
+ let matchResult, conditionalType_1;
521
+ if (matchValue != null) {
522
+ if (matchValue.tag === 33) {
523
+ matchResult = 0;
524
+ conditionalType_1 = matchValue.fields[0];
525
+ }
526
+ else {
527
+ matchResult = 1;
528
+ }
529
+ }
530
+ else {
531
+ matchResult = 1;
532
+ }
533
+ switch (matchResult) {
534
+ case 0:
535
+ return conditionalType_1;
536
+ default:
537
+ return undefined;
538
+ }
539
+ }
540
+ default:
541
+ return undefined;
542
+ }
543
+ }
544
+
545
+ function tryFindConditional(state, own, seen, glueType) {
546
+ const find = (glueType_1) => tryFindConditional(state, own, seen, glueType_1);
547
+ let matchValue_1;
548
+ const option_1 = inlineConditional(state, glueType);
549
+ if (option_1 != null) {
550
+ const conditionalType = option_1;
551
+ const matchValue = conditionalType.CheckType;
552
+ let matchResult, name_1;
553
+ if (matchValue.tag === 16) {
554
+ if (FSharpSet__Contains(own, matchValue.fields[0])) {
555
+ matchResult = 0;
556
+ name_1 = matchValue.fields[0];
557
+ }
558
+ else {
559
+ matchResult = 1;
560
+ }
561
+ }
562
+ else {
563
+ matchResult = 1;
564
+ }
565
+ switch (matchResult) {
566
+ case 0: {
567
+ matchValue_1 = [name_1, conditionalType];
568
+ break;
569
+ }
570
+ default:
571
+ matchValue_1 = undefined;
572
+ }
573
+ }
574
+ else {
575
+ matchValue_1 = undefined;
576
+ }
577
+ if (matchValue_1 == null) {
578
+ let matchResult_1, innerType;
579
+ switch (glueType.tag) {
580
+ case 13: {
581
+ matchResult_1 = 0;
582
+ break;
583
+ }
584
+ case 7: {
585
+ matchResult_1 = 1;
586
+ break;
587
+ }
588
+ case 14: {
589
+ matchResult_1 = 2;
590
+ innerType = glueType.fields[0];
591
+ break;
592
+ }
593
+ case 30: {
594
+ matchResult_1 = 2;
595
+ innerType = glueType.fields[0];
596
+ break;
597
+ }
598
+ case 23: {
599
+ matchResult_1 = 2;
600
+ innerType = glueType.fields[0];
601
+ break;
602
+ }
603
+ case 18: {
604
+ matchResult_1 = 3;
605
+ break;
606
+ }
607
+ case 15: {
608
+ matchResult_1 = 4;
609
+ break;
610
+ }
611
+ default:
612
+ matchResult_1 = 5;
613
+ }
614
+ switch (matchResult_1) {
615
+ case 0: {
616
+ const typeReference = glueType.fields[0];
617
+ const option_5 = tryPick(find, typeReference.TypeArguments);
618
+ if (option_5 != null) {
619
+ return option_5;
620
+ }
621
+ else if (FSharpSet__Contains(seen, typeReference.FullName)) {
622
+ return undefined;
623
+ }
624
+ else {
625
+ const option_2 = expandAlias(state, typeReference);
626
+ let binder_1;
627
+ const seen_1 = FSharpSet__Add(seen, typeReference.FullName);
628
+ binder_1 = ((glueType_2) => tryFindConditional(state, own, seen_1, glueType_2));
629
+ const option_3 = option_2;
630
+ if (option_3 != null) {
631
+ return binder_1(option_3);
632
+ }
633
+ else {
634
+ return undefined;
635
+ }
636
+ }
637
+ }
638
+ case 1:
639
+ return tryPick(find, glueType.fields[0].fields[0]);
640
+ case 2:
641
+ return find(innerType);
642
+ case 3:
643
+ return tryPick(find, glueType.fields[0]);
644
+ case 4: {
645
+ const functionType = glueType.fields[0];
646
+ const option_7 = tryPick((parameter) => find(parameter.Type), functionType.Parameters);
647
+ if (option_7 != null) {
648
+ return option_7;
649
+ }
650
+ else {
651
+ return find(functionType.Type);
652
+ }
653
+ }
654
+ default:
655
+ return undefined;
656
+ }
657
+ }
658
+ else {
659
+ return matchValue_1;
660
+ }
661
+ }
662
+
663
+ function branchesOf(checkType, conditionalType) {
664
+ const branch = [conditionalType.ExtendsType, conditionalType.TrueType, conditionalType.Inferred];
665
+ const matchValue = conditionalType.FalseType;
666
+ let matchResult, next_1, elseType_1;
667
+ if (matchValue.tag === 33) {
668
+ if (equals(matchValue.fields[0].CheckType, checkType)) {
669
+ matchResult = 0;
670
+ next_1 = matchValue.fields[0];
671
+ }
672
+ else {
673
+ matchResult = 1;
674
+ elseType_1 = matchValue;
675
+ }
676
+ }
677
+ else {
678
+ matchResult = 1;
679
+ elseType_1 = matchValue;
680
+ }
681
+ switch (matchResult) {
682
+ case 0: {
683
+ const patternInput = branchesOf(checkType, next_1);
684
+ return [cons(branch, patternInput[0]), patternInput[1]];
685
+ }
686
+ default:
687
+ return [singleton(branch), elseType_1];
688
+ }
689
+ }
690
+
691
+ function classify(state, checkedName, own, extends$, result, inferred) {
692
+ let typeReference_1;
693
+ const inferredNames = map_1((_arg) => _arg.Name, inferred);
694
+ const argumentNames = (extends$.tag === 13) ? choose((_arg_1) => {
695
+ let matchResult, name_1;
696
+ if (_arg_1.tag === 16) {
697
+ if (contains(_arg_1.fields[0], inferredNames, {
698
+ Equals: (x, y) => (x === y),
699
+ GetHashCode: (x) => (stringHash(x) | 0),
700
+ })) {
701
+ matchResult = 0;
702
+ name_1 = _arg_1.fields[0];
703
+ }
704
+ else {
705
+ matchResult = 1;
706
+ }
707
+ }
708
+ else {
709
+ matchResult = 1;
710
+ }
711
+ switch (matchResult) {
712
+ case 0:
713
+ return name_1;
714
+ default:
715
+ return undefined;
716
+ }
717
+ }, extends$.fields[0].TypeArguments) : empty_1();
718
+ if (equals(result, new GlueType(/* Primitive */ 3, [GluePrimitive.Never]))) {
719
+ return Branch.Nothing;
720
+ }
721
+ else if ((contains(checkedName, GlueSubstitution_mentionedTypeParameters(extends$), {
722
+ Equals: (x_1, y_1) => (x_1 === y_1),
723
+ GetHashCode: (x_1) => (stringHash(x_1) | 0),
724
+ }) ? true : mentionsConditional(state, result)) ? true : exists((value) => FSharpSet__Contains(own, value), inferredNames)) {
725
+ return Branch.Inexpressible;
726
+ }
727
+ else {
728
+ let matchResult_1, typeReference_2;
729
+ switch (extends$.tag) {
730
+ case 13: {
731
+ if ((typeReference_1 = extends$.fields[0], (!isEmpty(typeReference_1.TypeArguments) && (length(argumentNames) === length(typeReference_1.TypeArguments))) && equals(List_distinct(argumentNames, {
732
+ Equals: (x_2, y_2) => (x_2 === y_2),
733
+ GetHashCode: (x_2) => (stringHash(x_2) | 0),
734
+ }), inferredNames))) {
735
+ matchResult_1 = 0;
736
+ typeReference_2 = extends$.fields[0];
737
+ }
738
+ else {
739
+ matchResult_1 = 2;
740
+ }
741
+ break;
742
+ }
743
+ case 3: {
744
+ switch (extends$.fields[0].tag) {
745
+ case 0: {
746
+ if (isEmpty(inferred)) {
747
+ matchResult_1 = 1;
748
+ }
749
+ else {
750
+ matchResult_1 = 2;
751
+ }
752
+ break;
753
+ }
754
+ case 5: {
755
+ if (isEmpty(inferred)) {
756
+ matchResult_1 = 1;
757
+ }
758
+ else {
759
+ matchResult_1 = 2;
760
+ }
761
+ break;
762
+ }
763
+ case 3: {
764
+ if (isEmpty(inferred)) {
765
+ matchResult_1 = 1;
766
+ }
767
+ else {
768
+ matchResult_1 = 2;
769
+ }
770
+ break;
771
+ }
772
+ case 12: {
773
+ if (isEmpty(inferred)) {
774
+ matchResult_1 = 1;
775
+ }
776
+ else {
777
+ matchResult_1 = 2;
778
+ }
779
+ break;
780
+ }
781
+ default:
782
+ matchResult_1 = 2;
783
+ }
784
+ break;
785
+ }
786
+ default:
787
+ matchResult_1 = 2;
788
+ }
789
+ switch (matchResult_1) {
790
+ case 0:
791
+ return new Branch(/* Overload */ 0, [extends$, result, inferred]);
792
+ case 1:
793
+ return new Branch(/* Overload */ 0, [extends$, result, empty_1()]);
794
+ default:
795
+ return Branch.Inexpressible;
796
+ }
797
+ }
798
+ }
799
+
800
+ class Signature extends Record {
801
+ constructor(TypeParameters, Parameters, ReturnType) {
802
+ super();
803
+ this.TypeParameters = TypeParameters;
804
+ this.Parameters = Parameters;
805
+ this.ReturnType = ReturnType;
806
+ }
807
+ }
808
+
809
+ function Signature_$reflection() {
810
+ return record_type("Glutinum.Converter.Transformer.Conditionals.Signature", [], Signature, () => [["TypeParameters", list_type(GlueTypeParameter_$reflection())], ["Parameters", list_type(GlueParameter_$reflection())], ["ReturnType", GlueType_$reflection()]]);
811
+ }
812
+
813
+ function replaceConditional(state_mut, checkedName_mut, replacement_mut, seen_mut, glueType_mut) {
814
+ replaceConditional:
815
+ while (true) {
816
+ const state = state_mut, checkedName = checkedName_mut, replacement = replacement_mut, seen = seen_mut, glueType = glueType_mut;
817
+ let body, Parameters;
818
+ const replace = (glueType_1) => replaceConditional(state, checkedName, replacement, seen, glueType_1);
819
+ const matchValue = inlineConditional(state, glueType);
820
+ let matchResult, inlined_1;
821
+ if (matchValue != null) {
822
+ if (equals(matchValue.CheckType, new GlueType(/* TypeParameter */ 16, [checkedName]))) {
823
+ matchResult = 0;
824
+ inlined_1 = matchValue;
825
+ }
826
+ else {
827
+ matchResult = 1;
828
+ }
829
+ }
830
+ else {
831
+ matchResult = 1;
832
+ }
833
+ switch (matchResult) {
834
+ case 0:
835
+ return replacement;
836
+ default:
837
+ switch (glueType.tag) {
838
+ case 13: {
839
+ const typeReference = glueType.fields[0];
840
+ let body_1;
841
+ if (FSharpSet__Contains(seen, typeReference.FullName)) {
842
+ body_1 = undefined;
843
+ }
844
+ else {
845
+ const option_1 = expandAlias(state, typeReference);
846
+ body_1 = ((option_1 != null) ? (((body = option_1, tryFindConditional(state, ofSeq_1([checkedName], {
847
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
848
+ }), empty({
849
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
850
+ }), body) != null)) ? option_1 : undefined) : undefined);
851
+ }
852
+ if (body_1 == null) {
853
+ return new GlueType(/* TypeReference */ 13, [new GlueTypeReference(typeReference.Name, typeReference.FullName, typeReference.ModulePath, map_1(replace, typeReference.TypeArguments), typeReference.IsStandardLibrary)]);
854
+ }
855
+ else {
856
+ const body_2 = body_1;
857
+ state_mut = state;
858
+ checkedName_mut = checkedName;
859
+ replacement_mut = replacement;
860
+ seen_mut = FSharpSet__Add(seen, typeReference.FullName);
861
+ glueType_mut = body_2;
862
+ continue replaceConditional;
863
+ }
864
+ }
865
+ case 7:
866
+ return new GlueType(/* Union */ 7, [new GlueTypeUnion(map_1(replace, glueType.fields[0].fields[0]))]);
867
+ case 14:
868
+ return new GlueType(/* Array */ 14, [replace(glueType.fields[0])]);
869
+ case 30:
870
+ return new GlueType(/* ReadOnly */ 30, [replace(glueType.fields[0])]);
871
+ case 23:
872
+ return new GlueType(/* OptionalType */ 23, [replace(glueType.fields[0])]);
873
+ case 18:
874
+ return new GlueType(/* TupleType */ 18, [map_1(replace, glueType.fields[0])]);
875
+ case 15: {
876
+ const functionType = glueType.fields[0];
877
+ return new GlueType(/* FunctionType */ 15, [(Parameters = map_1((parameter) => (new GlueParameter(parameter.Name, parameter.IsOptional, parameter.IsSpread, replace(parameter.Type))), functionType.Parameters), new GlueFunctionType(functionType.Documentation, replace(functionType.Type), functionType.TypeParameters, functionType.OwnTypeParameterNames, Parameters))]);
878
+ }
879
+ default:
880
+ return glueType;
881
+ }
882
+ }
883
+ break;
884
+ }
885
+ }
886
+
887
+ function signatureWith(state, checkedName, replacement, substitutions, signature) {
888
+ const rewrite = (glueType) => GlueSubstitution_substitute(substitutions, replaceConditional(state, checkedName, replacement, empty({
889
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
890
+ }), glueType));
891
+ return new Signature(signature.TypeParameters, map_1((parameter) => (new GlueParameter(parameter.Name, parameter.IsOptional, parameter.IsSpread, rewrite(parameter.Type))), signature.Parameters), rewrite(signature.ReturnType));
892
+ }
893
+
894
+ function expandSignature(state, signature) {
895
+ const own = ofSeq_1(map_1((_arg) => _arg.Name, signature.TypeParameters), {
896
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
897
+ });
898
+ let found;
899
+ const option_1 = tryPick((parameter) => tryFindConditional(state, own, empty({
900
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
901
+ }), parameter.Type), signature.Parameters);
902
+ found = ((option_1 != null) ? option_1 : tryFindConditional(state, own, empty({
903
+ Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
904
+ }), signature.ReturnType));
905
+ if (found != null) {
906
+ const conditionalType = found[1];
907
+ const checkedName = found[0];
908
+ const patternInput = branchesOf(conditionalType.CheckType, conditionalType);
909
+ const classified = map_1((tupledArg) => classify(state, checkedName, own, tupledArg[0], tupledArg[1], tupledArg[2]), patternInput[0]);
910
+ const isTold = exists((parameter_1) => {
911
+ if (!parameter_1.IsOptional && !parameter_1.IsSpread) {
912
+ return equals(parameter_1.Type, new GlueType(/* TypeParameter */ 16, [checkedName]));
913
+ }
914
+ else {
915
+ return false;
916
+ }
917
+ }, signature.Parameters);
918
+ return List_distinct(append(choose((_arg_1) => {
919
+ let signature_1;
920
+ let matchResult, extends$_2, inferred_2, result_2;
921
+ switch (_arg_1.tag) {
922
+ case 1:
923
+ case 2: {
924
+ matchResult = 1;
925
+ break;
926
+ }
927
+ default:
928
+ if (isTold) {
929
+ matchResult = 0;
930
+ extends$_2 = _arg_1.fields[0];
931
+ inferred_2 = _arg_1.fields[2];
932
+ result_2 = _arg_1.fields[1];
933
+ }
934
+ else {
935
+ matchResult = 1;
936
+ }
937
+ }
938
+ switch (matchResult) {
939
+ case 0:
940
+ return (signature_1 = (new Signature(append(filter((typeParameter) => (typeParameter.Name !== checkedName), signature.TypeParameters), map_1((typeParameter_1) => (new GlueTypeParameter(typeParameter_1.Name, undefined, typeParameter_1.Default)), inferred_2)), signature.Parameters, signature.ReturnType)), signatureWith(state, checkedName, result_2, ofList(singleton([checkedName, extends$_2]), {
941
+ Compare: (x_3, y_3) => (comparePrimitives(x_3, y_3) | 0),
942
+ }), signature_1));
943
+ default:
944
+ return undefined;
945
+ }
946
+ }, classified), singleton(forAll((_arg_2) => {
947
+ switch (_arg_2.tag) {
948
+ case 0:
949
+ return isTold;
950
+ case 1:
951
+ return true;
952
+ default:
953
+ return false;
954
+ }
955
+ }, classified) ? signatureWith(state, checkedName, patternInput[1], empty_2({
956
+ Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
957
+ }), signature) : signature)), {
958
+ Equals: equals,
959
+ GetHashCode: (x_5) => (safeHash(x_5) | 0),
960
+ });
961
+ }
962
+ else {
963
+ return singleton(signature);
964
+ }
965
+ }
966
+
967
+ function restArray(state, glueType) {
968
+ let typeReference;
969
+ let matchResult, typeReference_1;
970
+ if (glueType.tag === 13) {
971
+ if ((typeReference = glueType.fields[0], FSharpMap__ContainsKey(state.AllAliases, typeReference.FullName) && isEmpty(typeReference.TypeArguments))) {
972
+ matchResult = 0;
973
+ typeReference_1 = glueType.fields[0];
974
+ }
975
+ else {
976
+ matchResult = 1;
977
+ }
978
+ }
979
+ else {
980
+ matchResult = 1;
981
+ }
982
+ switch (matchResult) {
983
+ case 0: {
984
+ const matchValue = FSharpMap__get_Item(state.AllAliases, typeReference_1.FullName).Type;
985
+ let matchResult_1, elementType;
986
+ switch (matchValue.tag) {
987
+ case 18: {
988
+ if (!isEmpty(matchValue.fields[0])) {
989
+ switch (head_2(matchValue.fields[0]).tag) {
990
+ case 19: {
991
+ if (head_2(matchValue.fields[0]).fields[0].Type.tag === 14) {
992
+ if (isEmpty(tail(matchValue.fields[0]))) {
993
+ matchResult_1 = 0;
994
+ elementType = head_2(matchValue.fields[0]).fields[0].Type.fields[0];
995
+ }
996
+ else {
997
+ matchResult_1 = 1;
998
+ }
999
+ }
1000
+ else {
1001
+ matchResult_1 = 1;
1002
+ }
1003
+ break;
1004
+ }
1005
+ case 14: {
1006
+ if (isEmpty(tail(matchValue.fields[0]))) {
1007
+ matchResult_1 = 0;
1008
+ elementType = head_2(matchValue.fields[0]).fields[0];
1009
+ }
1010
+ else {
1011
+ matchResult_1 = 1;
1012
+ }
1013
+ break;
1014
+ }
1015
+ default:
1016
+ matchResult_1 = 1;
1017
+ }
1018
+ }
1019
+ else {
1020
+ matchResult_1 = 1;
1021
+ }
1022
+ break;
1023
+ }
1024
+ case 14: {
1025
+ matchResult_1 = 0;
1026
+ elementType = matchValue.fields[0];
1027
+ break;
1028
+ }
1029
+ default:
1030
+ matchResult_1 = 1;
1031
+ }
1032
+ switch (matchResult_1) {
1033
+ case 0:
1034
+ return new GlueType(/* Array */ 14, [elementType]);
1035
+ default:
1036
+ return glueType;
1037
+ }
1038
+ }
1039
+ default:
1040
+ return glueType;
1041
+ }
1042
+ }
1043
+
1044
+ function resolveParameters(state, parameters) {
1045
+ if (FSharpMap__get_IsEmpty(state.Aliases)) {
1046
+ return parameters;
1047
+ }
1048
+ else {
1049
+ return map_1((parameter) => {
1050
+ const resolved = resolve(state, parameter.Type);
1051
+ return new GlueParameter(parameter.Name, parameter.IsOptional, parameter.IsSpread, parameter.IsSpread ? restArray(state, resolved) : resolved);
1052
+ }, parameters);
1053
+ }
1054
+ }
1055
+
1056
+ /**
1057
+ * The members of a declaration, the conditional types left deferred collapsed, the ones over
1058
+ * an own type parameter expanded into overloads
1059
+ */
1060
+ export function resolveMembers(state, members) {
1061
+ return collect_1((glueMember) => {
1062
+ switch (glueMember.tag) {
1063
+ case 0: {
1064
+ const info = glueMember.fields[0];
1065
+ return map_1((signature) => (new GlueMember(/* Method */ 0, [new GlueMethod(info.Name, info.Documentation, signature.TypeParameters, resolveParameters(state, signature.Parameters), resolve(state, signature.ReturnType), info.IsOptional, info.IsStatic)])), expandSignature(state, new Signature(info.TypeParameters, info.Parameters, info.Type)));
1066
+ }
1067
+ case 6: {
1068
+ const info_1 = glueMember.fields[0];
1069
+ return map_1((signature_1) => (new GlueMember(/* MethodSignature */ 6, [new GlueMethodSignature(info_1.Name, info_1.Documentation, signature_1.TypeParameters, resolveParameters(state, signature_1.Parameters), resolve(state, signature_1.ReturnType), info_1.IsOptional)])), expandSignature(state, new Signature(info_1.TypeParameters, info_1.Parameters, info_1.Type)));
1070
+ }
1071
+ case 1: {
1072
+ const info_2 = glueMember.fields[0];
1073
+ return singleton(new GlueMember(/* Property */ 1, [new GlueProperty(info_2.Name, info_2.Documentation, resolve(state, info_2.Type), info_2.IsStatic, info_2.IsOptional, info_2.Accessor, info_2.IsPrivate)]));
1074
+ }
1075
+ default:
1076
+ return singleton(glueMember);
1077
+ }
1078
+ }, members);
1079
+ }
1080
+
1081
+ export function resolveFunction(state, info) {
1082
+ return map_1((signature) => {
1083
+ const Parameters = resolveParameters(state, signature.Parameters);
1084
+ return new GlueFunctionDeclaration(info.Documentation, info.IsDeclared, info.Name, resolve(state, signature.ReturnType), Parameters, signature.TypeParameters);
1085
+ }, expandSignature(state, new Signature(info.TypeParameters, info.Parameters, info.Type)));
1086
+ }
1087
+