@glutinum/cli 1.0.0-beta.2 → 1.0.0-beta.3
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.
- package/README.md +16 -0
- package/dist/Glutinum.Converter/Abbreviations.js +9 -32
- package/dist/Glutinum.Converter/DelegateExtensions.js +378 -0
- package/dist/Glutinum.Converter/FreeTypeParameters.js +211 -0
- package/dist/Glutinum.Converter/FsharpAST.js +116 -65
- package/dist/Glutinum.Converter/Generate.js +34 -21
- package/dist/Glutinum.Converter/GlueAST.js +79 -41
- package/dist/Glutinum.Converter/Hosting.js +132 -157
- package/dist/Glutinum.Converter/Merge.js +369 -337
- package/dist/Glutinum.Converter/Packages.js +391 -92
- package/dist/Glutinum.Converter/Printer.js +396 -423
- package/dist/Glutinum.Converter/Read.js +387 -88
- package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +4 -4
- package/dist/Glutinum.Converter/Reader/Declaration.js +6 -12
- package/dist/Glutinum.Converter/Reader/Documentation.js +23 -35
- package/dist/Glutinum.Converter/Reader/ExportAssignment.js +103 -36
- package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +21 -36
- package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +26 -13
- package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +14 -20
- package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +45 -2
- package/dist/Glutinum.Converter/Reader/Node.js +8 -11
- package/dist/Glutinum.Converter/Reader/Parameters.js +34 -26
- package/dist/Glutinum.Converter/Reader/TypeNode.js +1988 -1342
- package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +32 -44
- package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +14 -37
- package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +23 -5
- package/dist/Glutinum.Converter/Reader/Types.js +290 -15
- package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +14 -28
- package/dist/Glutinum.Converter/Reader/Utils.js +325 -25
- package/dist/Glutinum.Converter/Reader/VariableStatement.js +2 -3
- package/dist/Glutinum.Converter/Transform.js +3568 -8456
- package/dist/Glutinum.Converter/Transformer/AnyFunctionOverloads.js +116 -0
- package/dist/Glutinum.Converter/Transformer/CallableProperties.js +454 -0
- package/dist/Glutinum.Converter/Transformer/Comment.js +136 -0
- package/dist/Glutinum.Converter/Transformer/Conditionals.js +1149 -0
- package/dist/Glutinum.Converter/Transformer/Context.js +666 -0
- package/dist/Glutinum.Converter/Transformer/Enum.js +80 -0
- package/dist/Glutinum.Converter/Transformer/Heritage.js +406 -0
- package/dist/Glutinum.Converter/Transformer/KeyOfMaps.js +488 -0
- package/dist/Glutinum.Converter/Transformer/ParamObjectCandidate.js +596 -0
- package/dist/Glutinum.Converter/Transformer/TypeParameters.js +448 -0
- package/dist/Glutinum.Converter/Transformer/UnionOverloads.js +353 -0
- package/dist/Glutinum.Converter/Transformer/Utils.js +341 -0
- package/dist/Glutinum.Converter/TypeScript.Extensions.js +0 -10
- package/dist/Glutinum.Converter/Utils/String.js +14 -3
- package/dist/Program.js +18 -10
- package/package.json +1 -1
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
|
|
2
|
+
import { takeWhile, ofArray, mapIndexed, append, fold, tryFindIndex, empty, zip, tail as tail_1, head as head_1, tryFind, choose, forAll, filter, isEmpty, length, tryPick, map, exists, cons, singleton, collect } from "../../fable_modules/fable-library-js.5.17.2/List.js";
|
|
3
|
+
import { GlueConstructSignature, GlueMethod, GlueMember, GlueMethodSignature, GlueParameter, GlueTypeUnion, GlueSubstitution_substitute, GlueType, GluePrimitive } from "../GlueAST.js";
|
|
4
|
+
import { List_distinct } from "../../fable_modules/fable-library-js.5.17.2/Seq2.js";
|
|
5
|
+
import { defaultArg } from "../../fable_modules/fable-library-js.5.17.2/Option.js";
|
|
6
|
+
import { comparePrimitives, safeHash, equals } from "../../fable_modules/fable-library-js.5.17.2/Util.js";
|
|
7
|
+
import { ofList } from "../../fable_modules/fable-library-js.5.17.2/Map.js";
|
|
8
|
+
import { map as map_1, empty as empty_1, singleton as singleton_1, append as append_1, delay, toList } from "../../fable_modules/fable-library-js.5.17.2/Seq.js";
|
|
9
|
+
|
|
10
|
+
export const defaultMaxOverloads = 16;
|
|
11
|
+
|
|
12
|
+
function isNullish(glueType) {
|
|
13
|
+
let matchResult;
|
|
14
|
+
if (glueType.tag === 3) {
|
|
15
|
+
switch (glueType.fields[0].tag) {
|
|
16
|
+
case 7:
|
|
17
|
+
case 8: {
|
|
18
|
+
matchResult = 0;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
default:
|
|
22
|
+
matchResult = 1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
matchResult = 1;
|
|
27
|
+
}
|
|
28
|
+
switch (matchResult) {
|
|
29
|
+
case 0:
|
|
30
|
+
return true;
|
|
31
|
+
default:
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function tryCases(typeMemory_mut, glueType_mut) {
|
|
37
|
+
tryCases:
|
|
38
|
+
while (true) {
|
|
39
|
+
const typeMemory = typeMemory_mut, glueType = glueType_mut;
|
|
40
|
+
let matchResult, cases, union, typeReference_2;
|
|
41
|
+
switch (glueType.tag) {
|
|
42
|
+
case 7: {
|
|
43
|
+
matchResult = 0;
|
|
44
|
+
cases = glueType.fields[0].fields[0];
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case 5: {
|
|
48
|
+
if (glueType.fields[0].Type.tag === 7) {
|
|
49
|
+
if (isEmpty(glueType.fields[0].TypeParameters)) {
|
|
50
|
+
matchResult = 1;
|
|
51
|
+
union = glueType.fields[0].Type;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
matchResult = 3;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
matchResult = 3;
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case 13: {
|
|
63
|
+
matchResult = 2;
|
|
64
|
+
typeReference_2 = glueType.fields[0];
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
default:
|
|
68
|
+
matchResult = 3;
|
|
69
|
+
}
|
|
70
|
+
switch (matchResult) {
|
|
71
|
+
case 0: {
|
|
72
|
+
const cases_1 = collect((case$) => {
|
|
73
|
+
switch (case$.tag) {
|
|
74
|
+
case 13:
|
|
75
|
+
case 5: {
|
|
76
|
+
const matchValue = tryCases(typeMemory, case$);
|
|
77
|
+
if (matchValue == null) {
|
|
78
|
+
return singleton(case$);
|
|
79
|
+
}
|
|
80
|
+
else if (matchValue[1]) {
|
|
81
|
+
const aliasCases = matchValue[0];
|
|
82
|
+
return cons(new GlueType(/* Primitive */ 3, [GluePrimitive.Null]), aliasCases);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const aliasCases_1 = matchValue[0];
|
|
86
|
+
return aliasCases_1;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
default:
|
|
90
|
+
return singleton(case$);
|
|
91
|
+
}
|
|
92
|
+
}, cases);
|
|
93
|
+
const nullable = exists(isNullish, cases_1);
|
|
94
|
+
const cases_2 = List_distinct(map((case$_1) => {
|
|
95
|
+
let matchResult_1, typeReference_1;
|
|
96
|
+
if (case$_1.tag === 13) {
|
|
97
|
+
if (isEmpty(case$_1.fields[0].TypeArguments)) {
|
|
98
|
+
matchResult_1 = 0;
|
|
99
|
+
typeReference_1 = case$_1.fields[0];
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
matchResult_1 = 1;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
matchResult_1 = 1;
|
|
107
|
+
}
|
|
108
|
+
switch (matchResult_1) {
|
|
109
|
+
case 0:
|
|
110
|
+
return defaultArg(tryPick((_arg) => {
|
|
111
|
+
let aliasCases_2;
|
|
112
|
+
let matchResult_2, aliasCases_3, fullName_1;
|
|
113
|
+
if (_arg.tag === 5) {
|
|
114
|
+
if (_arg.fields[0].Type.tag === 7) {
|
|
115
|
+
if ((aliasCases_2 = _arg.fields[0].Type.fields[0].fields[0], ((_arg.fields[0].FullName === typeReference_1.FullName) && (length(aliasCases_2) > 9)) && exists((_arg_1) => {
|
|
116
|
+
if (_arg_1.tag === 8) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
}, aliasCases_2))) {
|
|
123
|
+
matchResult_2 = 0;
|
|
124
|
+
aliasCases_3 = _arg.fields[0].Type.fields[0].fields[0];
|
|
125
|
+
fullName_1 = _arg.fields[0].FullName;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
matchResult_2 = 1;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
matchResult_2 = 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
matchResult_2 = 1;
|
|
137
|
+
}
|
|
138
|
+
switch (matchResult_2) {
|
|
139
|
+
case 0:
|
|
140
|
+
return new GlueType(/* Primitive */ 3, [GluePrimitive.Any]);
|
|
141
|
+
default:
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
}, typeMemory), case$_1);
|
|
145
|
+
default:
|
|
146
|
+
return case$_1;
|
|
147
|
+
}
|
|
148
|
+
}, filter((arg) => !isNullish(arg), cases_1)), {
|
|
149
|
+
Equals: equals,
|
|
150
|
+
GetHashCode: (x) => (safeHash(x) | 0),
|
|
151
|
+
});
|
|
152
|
+
if (((length(cases_2) >= 2) && (length(cases_2) <= 9)) && forAll((_arg_2) => {
|
|
153
|
+
if (_arg_2.tag === 8) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
}, cases_2)) {
|
|
160
|
+
return [cases_2, nullable];
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
case 1: {
|
|
167
|
+
typeMemory_mut = typeMemory;
|
|
168
|
+
glueType_mut = union;
|
|
169
|
+
continue tryCases;
|
|
170
|
+
}
|
|
171
|
+
case 2: {
|
|
172
|
+
const arity = length(typeReference_2.TypeArguments) | 0;
|
|
173
|
+
const unionAliases = choose((_arg_3) => {
|
|
174
|
+
let matchResult_3, alias_1;
|
|
175
|
+
if (_arg_3.tag === 5) {
|
|
176
|
+
if (_arg_3.fields[0].Type.tag === 7) {
|
|
177
|
+
if (length(_arg_3.fields[0].TypeParameters) === arity) {
|
|
178
|
+
matchResult_3 = 0;
|
|
179
|
+
alias_1 = _arg_3.fields[0];
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
matchResult_3 = 1;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
matchResult_3 = 1;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
matchResult_3 = 1;
|
|
191
|
+
}
|
|
192
|
+
switch (matchResult_3) {
|
|
193
|
+
case 0:
|
|
194
|
+
return alias_1;
|
|
195
|
+
default:
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
}, typeMemory);
|
|
199
|
+
let option_4;
|
|
200
|
+
const option_2 = tryFind((alias_2) => (alias_2.FullName === typeReference_2.FullName), unionAliases);
|
|
201
|
+
if (option_2 != null) {
|
|
202
|
+
option_4 = option_2;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
const matchValue_1 = filter((alias_3) => (alias_3.Name === typeReference_2.Name), unionAliases);
|
|
206
|
+
let matchResult_4, alias_5, others_1;
|
|
207
|
+
if (!isEmpty(matchValue_1)) {
|
|
208
|
+
if (forAll((other) => equals(other.Type, head_1(matchValue_1).Type), tail_1(matchValue_1))) {
|
|
209
|
+
matchResult_4 = 0;
|
|
210
|
+
alias_5 = head_1(matchValue_1);
|
|
211
|
+
others_1 = tail_1(matchValue_1);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
matchResult_4 = 1;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
matchResult_4 = 1;
|
|
219
|
+
}
|
|
220
|
+
switch (matchResult_4) {
|
|
221
|
+
case 0: {
|
|
222
|
+
option_4 = alias_5;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
default:
|
|
226
|
+
option_4 = undefined;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (option_4 != null) {
|
|
230
|
+
const alias_6 = option_4;
|
|
231
|
+
typeMemory_mut = typeMemory;
|
|
232
|
+
glueType_mut = GlueSubstitution_substitute(ofList(zip(map((_arg_4) => _arg_4.Name, alias_6.TypeParameters), typeReference_2.TypeArguments), {
|
|
233
|
+
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
234
|
+
}), alias_6.Type);
|
|
235
|
+
continue tryCases;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
default:
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function cartesian(choices) {
|
|
249
|
+
if (!isEmpty(choices)) {
|
|
250
|
+
const rest = cartesian(tail_1(choices));
|
|
251
|
+
return collect((choice) => map((combination) => cons(choice, combination), rest), head_1(choices));
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
return singleton(empty());
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* The parameter lists of the overloads, the original one when nothing is expanded
|
|
260
|
+
*/
|
|
261
|
+
export function expandParameters(maxOverloads, typeMemory, parameters) {
|
|
262
|
+
const firstOptionalKept = tryFindIndex((parameter) => {
|
|
263
|
+
if (parameter.IsOptional) {
|
|
264
|
+
return tryCases(typeMemory, parameter.Type) == null;
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
}, parameters);
|
|
270
|
+
const patternInput = fold((tupledArg, tupledArg_1) => {
|
|
271
|
+
const acc = tupledArg[0];
|
|
272
|
+
const count = tupledArg[1] | 0;
|
|
273
|
+
const choice = tupledArg_1[0];
|
|
274
|
+
if ((count * length(choice)) <= maxOverloads) {
|
|
275
|
+
return [append(acc, singleton(choice)), count * length(choice)];
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
return [append(acc, singleton(singleton(tupledArg_1[1]))), count];
|
|
279
|
+
}
|
|
280
|
+
}, [empty(), 1], zip(mapIndexed((index, parameter_1) => {
|
|
281
|
+
const afterOptional = (firstOptionalKept == null) ? false : (index > firstOptionalKept);
|
|
282
|
+
const matchValue = tryCases(typeMemory, parameter_1.Type);
|
|
283
|
+
let matchResult, cases_1, nullable_1;
|
|
284
|
+
if (matchValue != null) {
|
|
285
|
+
if ((matchValue[1], matchValue[0], !afterOptional)) {
|
|
286
|
+
matchResult = 0;
|
|
287
|
+
cases_1 = matchValue[0];
|
|
288
|
+
nullable_1 = matchValue[1];
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
matchResult = 1;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
matchResult = 1;
|
|
296
|
+
}
|
|
297
|
+
switch (matchResult) {
|
|
298
|
+
case 0:
|
|
299
|
+
return toList(delay(() => append_1(parameter_1.IsOptional ? singleton_1(undefined) : empty_1(), delay(() => map_1((case$) => (new GlueParameter(parameter_1.Name, false, parameter_1.IsSpread, (nullable_1 && !parameter_1.IsOptional) ? (new GlueType(/* Union */ 7, [new GlueTypeUnion(ofArray([case$, new GlueType(/* Primitive */ 3, [GluePrimitive.Undefined])]))])) : case$)), cases_1)))));
|
|
300
|
+
default:
|
|
301
|
+
return singleton(parameter_1);
|
|
302
|
+
}
|
|
303
|
+
}, parameters), parameters));
|
|
304
|
+
const choices_1 = patternInput[0];
|
|
305
|
+
const expandsAnOptional = exists((tupledArg_2) => {
|
|
306
|
+
if (tupledArg_2[1].IsOptional) {
|
|
307
|
+
return length(tupledArg_2[0]) > 1;
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
}, zip(choices_1, parameters));
|
|
313
|
+
if (patternInput[1] <= 1) {
|
|
314
|
+
return singleton(parameters);
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
const expanded = List_distinct(map((combination) => choose((x) => x, takeWhile((option) => (option != null), combination)), cartesian(choices_1)), {
|
|
318
|
+
Equals: equals,
|
|
319
|
+
GetHashCode: (x_1) => (safeHash(x_1) | 0),
|
|
320
|
+
});
|
|
321
|
+
if (expandsAnOptional) {
|
|
322
|
+
return expanded;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
return List_distinct(append(expanded, singleton(parameters)), {
|
|
326
|
+
Equals: equals,
|
|
327
|
+
GetHashCode: (x_2) => (safeHash(x_2) | 0),
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export function expandMembers(maxOverloads, typeMemory, members) {
|
|
334
|
+
return collect((glueMember) => {
|
|
335
|
+
switch (glueMember.tag) {
|
|
336
|
+
case 6: {
|
|
337
|
+
const info = glueMember.fields[0];
|
|
338
|
+
return map((parameters) => (new GlueMember(/* MethodSignature */ 6, [new GlueMethodSignature(info.Name, info.Documentation, info.TypeParameters, parameters, info.Type, info.IsOptional)])), expandParameters(maxOverloads, typeMemory, info.Parameters));
|
|
339
|
+
}
|
|
340
|
+
case 0: {
|
|
341
|
+
const info_1 = glueMember.fields[0];
|
|
342
|
+
return map((parameters_1) => (new GlueMember(/* Method */ 0, [new GlueMethod(info_1.Name, info_1.Documentation, info_1.TypeParameters, parameters_1, info_1.Type, info_1.IsOptional, info_1.IsStatic)])), expandParameters(maxOverloads, typeMemory, info_1.Parameters));
|
|
343
|
+
}
|
|
344
|
+
case 7: {
|
|
345
|
+
const info_2 = glueMember.fields[0];
|
|
346
|
+
return map((parameters_2) => (new GlueMember(/* ConstructSignature */ 7, [new GlueConstructSignature(parameters_2, info_2.Type)])), expandParameters(maxOverloads, typeMemory, info_2.Parameters));
|
|
347
|
+
}
|
|
348
|
+
default:
|
|
349
|
+
return singleton(glueMember);
|
|
350
|
+
}
|
|
351
|
+
}, members);
|
|
352
|
+
}
|
|
353
|
+
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
|
|
2
|
+
import { FSharpSet__Contains, ofSeq } from "../../fable_modules/fable-library-js.5.17.2/Set.js";
|
|
3
|
+
import { safeHash, equals, comparePrimitives } from "../../fable_modules/fable-library-js.5.17.2/Util.js";
|
|
4
|
+
import { FSharpModule, FSharpTypeAlias, FSharpMapped, FSharpInterface, FSharpMember, FSharpMemberInfo, FSharpParameter, FSharpAttribute, FSharpPrimitive, FSharpLiteral, FSharpType, FSharpUnion } from "../FsharpAST.js";
|
|
5
|
+
import { singleton as singleton_1, ofArray, isEmpty, empty, tryPick, collect, map, exists, contains, forAll } from "../../fable_modules/fable-library-js.5.17.2/List.js";
|
|
6
|
+
import { GlueTypeUnion, GlueTypeReference, GlueType, GluePrimitive } from "../GlueAST.js";
|
|
7
|
+
import { concat } from "../../fable_modules/fable-library-js.5.17.2/String.js";
|
|
8
|
+
import { empty as empty_1, singleton, append, delay, toList } from "../../fable_modules/fable-library-js.5.17.2/Seq.js";
|
|
9
|
+
import { toArray } from "../../fable_modules/fable-library-js.5.17.2/Option.js";
|
|
10
|
+
|
|
11
|
+
export const typedArrayNames = ofSeq(["Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array"], {
|
|
12
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const iteratorNames = ofSeq(["IterableIterator", "IteratorObject", "ArrayIterator", "MapIterator", "SetIterator", "StringIterator"], {
|
|
16
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export function tryUnwrapOption(typ) {
|
|
20
|
+
let matchResult, underlyingType, unionInfo_1;
|
|
21
|
+
switch (typ.tag) {
|
|
22
|
+
case 3: {
|
|
23
|
+
matchResult = 0;
|
|
24
|
+
underlyingType = typ.fields[0];
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case 1: {
|
|
28
|
+
if (typ.fields[0].IsOptional) {
|
|
29
|
+
matchResult = 1;
|
|
30
|
+
unionInfo_1 = typ.fields[0];
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
matchResult = 2;
|
|
34
|
+
}
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
default:
|
|
38
|
+
matchResult = 2;
|
|
39
|
+
}
|
|
40
|
+
switch (matchResult) {
|
|
41
|
+
case 0:
|
|
42
|
+
return underlyingType;
|
|
43
|
+
case 1:
|
|
44
|
+
return new FSharpType(/* Union */ 1, [new FSharpUnion(unionInfo_1.Attributes, unionInfo_1.Name, unionInfo_1.Cases, false, unionInfo_1.TypeParameters, unionInfo_1.Constants)]);
|
|
45
|
+
default:
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const unionCaseNames = ofSeq(["None", "Some", "Ok", "Error", "ValueNone", "ValueSome"], {
|
|
51
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
export function isUnionCaseName(name) {
|
|
55
|
+
return FSharpSet__Contains(unionCaseNames, name);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function isDataObject(members) {
|
|
59
|
+
return forAll((_arg) => {
|
|
60
|
+
switch (_arg.tag) {
|
|
61
|
+
case 1:
|
|
62
|
+
return !isUnionCaseName(_arg.fields[0].Name);
|
|
63
|
+
case 6:
|
|
64
|
+
case 2:
|
|
65
|
+
case 3:
|
|
66
|
+
case 0:
|
|
67
|
+
return true;
|
|
68
|
+
default:
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}, members);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function transformLiteral(glueLiteral) {
|
|
75
|
+
switch (glueLiteral.tag) {
|
|
76
|
+
case 1:
|
|
77
|
+
return new FSharpLiteral(/* Int */ 1, [glueLiteral.fields[0]]);
|
|
78
|
+
case 2:
|
|
79
|
+
return new FSharpLiteral(/* Float */ 2, [glueLiteral.fields[0]]);
|
|
80
|
+
case 3:
|
|
81
|
+
return new FSharpLiteral(/* Bool */ 3, [glueLiteral.fields[0]]);
|
|
82
|
+
case 4:
|
|
83
|
+
return FSharpLiteral.Null;
|
|
84
|
+
default:
|
|
85
|
+
return new FSharpLiteral(/* String */ 0, [glueLiteral.fields[0]]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function transformPrimitive(gluePrimitive) {
|
|
90
|
+
switch (gluePrimitive.tag) {
|
|
91
|
+
case 1:
|
|
92
|
+
return FSharpPrimitive.Int;
|
|
93
|
+
case 2:
|
|
94
|
+
return FSharpPrimitive.Float;
|
|
95
|
+
case 3:
|
|
96
|
+
return FSharpPrimitive.Bool;
|
|
97
|
+
case 4:
|
|
98
|
+
return FSharpPrimitive.Unit;
|
|
99
|
+
case 5:
|
|
100
|
+
return FSharpPrimitive.Number$;
|
|
101
|
+
case 6:
|
|
102
|
+
return FSharpPrimitive.Null;
|
|
103
|
+
case 7:
|
|
104
|
+
return FSharpPrimitive.Null;
|
|
105
|
+
case 8:
|
|
106
|
+
return FSharpPrimitive.Null;
|
|
107
|
+
case 9:
|
|
108
|
+
return FSharpPrimitive.Null;
|
|
109
|
+
case 10:
|
|
110
|
+
return FSharpPrimitive.Null;
|
|
111
|
+
case 12:
|
|
112
|
+
return FSharpPrimitive.BigInt$;
|
|
113
|
+
case 11:
|
|
114
|
+
return FSharpPrimitive.Null;
|
|
115
|
+
default:
|
|
116
|
+
return FSharpPrimitive.String$;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function requiredBeforeParamArray(parameters) {
|
|
121
|
+
const isParamArray = (parameter) => contains(FSharpAttribute.ParamArray, parameter.Attributes, {
|
|
122
|
+
Equals: equals,
|
|
123
|
+
GetHashCode: (x) => (safeHash(x) | 0),
|
|
124
|
+
});
|
|
125
|
+
if (exists(isParamArray, parameters)) {
|
|
126
|
+
return map((parameter_1) => {
|
|
127
|
+
if (isParamArray(parameter_1)) {
|
|
128
|
+
return parameter_1;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
return new FSharpParameter(parameter_1.Attributes, parameter_1.Name, false, parameter_1.Type, parameter_1.OriginalGlueMember);
|
|
132
|
+
}
|
|
133
|
+
}, parameters);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
return parameters;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* `type Key = string | Key[]`: an F# abbreviation can't refer to itself
|
|
142
|
+
*/
|
|
143
|
+
export function replaceSelfReference(name, glueType) {
|
|
144
|
+
let typeReference;
|
|
145
|
+
const replace = (glueType_1) => replaceSelfReference(name, glueType_1);
|
|
146
|
+
switch (glueType.tag) {
|
|
147
|
+
case 13:
|
|
148
|
+
if ((typeReference = glueType.fields[0], (typeReference.Name === name) && !typeReference.IsStandardLibrary)) {
|
|
149
|
+
return new GlueType(/* Primitive */ 3, [GluePrimitive.Any]);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
return new GlueType(/* TypeReference */ 13, [new GlueTypeReference(glueType.fields[0].Name, glueType.fields[0].FullName, glueType.fields[0].ModulePath, map(replace, glueType.fields[0].TypeArguments), glueType.fields[0].IsStandardLibrary)]);
|
|
153
|
+
}
|
|
154
|
+
case 7:
|
|
155
|
+
return new GlueType(/* Union */ 7, [new GlueTypeUnion(map(replace, glueType.fields[0].fields[0]))]);
|
|
156
|
+
case 14:
|
|
157
|
+
return new GlueType(/* Array */ 14, [replace(glueType.fields[0])]);
|
|
158
|
+
case 30:
|
|
159
|
+
return new GlueType(/* ReadOnly */ 30, [replace(glueType.fields[0])]);
|
|
160
|
+
case 23:
|
|
161
|
+
return new GlueType(/* OptionalType */ 23, [replace(glueType.fields[0])]);
|
|
162
|
+
case 18:
|
|
163
|
+
return new GlueType(/* TupleType */ 18, [map(replace, glueType.fields[0])]);
|
|
164
|
+
default:
|
|
165
|
+
return glueType;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function Interface_makePartial(name, originalInterface) {
|
|
170
|
+
return new FSharpInterface(originalInterface.Attributes, name, originalInterface.XmlDoc, originalInterface.OriginalName, originalInterface.TypeParameters, map((m) => {
|
|
171
|
+
if (m.tag === 1) {
|
|
172
|
+
const property = m.fields[0];
|
|
173
|
+
const matchValue = tryUnwrapOption(property.Type);
|
|
174
|
+
if (matchValue == null) {
|
|
175
|
+
return new FSharpMember(/* Property */ 1, [new FSharpMemberInfo(property.Attributes, property.Name, property.OriginalName, property.TypeParameters, property.Parameters, property.Type, true, property.IsStatic, property.Accessor, property.Accessibility, property.XmlDoc, property.Body)]);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
return m;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
return m;
|
|
183
|
+
}
|
|
184
|
+
}, originalInterface.Members), originalInterface.Inheritance);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* `type Payload = void`, a property of that type can't have a setter either
|
|
189
|
+
*/
|
|
190
|
+
export function isUnitAlias(typeMemory, fullName) {
|
|
191
|
+
return exists((_arg) => {
|
|
192
|
+
let matchResult, aliasFullName;
|
|
193
|
+
if (_arg.tag === 5) {
|
|
194
|
+
if (_arg.fields[0].Type.tag === 3) {
|
|
195
|
+
if (_arg.fields[0].Type.fields[0].tag === 4) {
|
|
196
|
+
matchResult = 0;
|
|
197
|
+
aliasFullName = _arg.fields[0].FullName;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
matchResult = 1;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
matchResult = 1;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
matchResult = 1;
|
|
209
|
+
}
|
|
210
|
+
switch (matchResult) {
|
|
211
|
+
case 0:
|
|
212
|
+
return aliasFullName === fullName;
|
|
213
|
+
default:
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
}, typeMemory);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function aggregatedExports(types) {
|
|
220
|
+
const hasEntryExports = exists((_arg) => {
|
|
221
|
+
let matchResult, members;
|
|
222
|
+
if (_arg.tag === 5) {
|
|
223
|
+
if (_arg.fields[0].Name === "Exports") {
|
|
224
|
+
matchResult = 0;
|
|
225
|
+
members = _arg.fields[0].Members;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
matchResult = 1;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
matchResult = 1;
|
|
233
|
+
}
|
|
234
|
+
switch (matchResult) {
|
|
235
|
+
case 0: {
|
|
236
|
+
const isGlobal = (attributes) => exists((_arg_1) => {
|
|
237
|
+
if (_arg_1.tag === 21) {
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
}, attributes);
|
|
244
|
+
return exists((_arg_2) => {
|
|
245
|
+
let matchResult_1, info_1;
|
|
246
|
+
switch (_arg_2.tag) {
|
|
247
|
+
case 1: {
|
|
248
|
+
matchResult_1 = 0;
|
|
249
|
+
info_1 = _arg_2.fields[0];
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
case 2: {
|
|
253
|
+
matchResult_1 = 1;
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
default: {
|
|
257
|
+
matchResult_1 = 0;
|
|
258
|
+
info_1 = _arg_2.fields[0];
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
switch (matchResult_1) {
|
|
262
|
+
case 0:
|
|
263
|
+
return !isGlobal(info_1.Attributes);
|
|
264
|
+
default:
|
|
265
|
+
return !isGlobal(_arg_2.fields[0].Attributes);
|
|
266
|
+
}
|
|
267
|
+
}, members);
|
|
268
|
+
}
|
|
269
|
+
default:
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
}, types);
|
|
273
|
+
const abbreviationsOf = (path, types_1) => collect((_arg_3) => {
|
|
274
|
+
if (_arg_3.tag === 4) {
|
|
275
|
+
const fileModule = _arg_3.fields[0];
|
|
276
|
+
const own = tryPick((_arg_4) => {
|
|
277
|
+
let members_1;
|
|
278
|
+
let matchResult_2, members_2;
|
|
279
|
+
if (_arg_4.tag === 5) {
|
|
280
|
+
if (_arg_4.fields[0].Name === "Exports") {
|
|
281
|
+
if ((members_1 = _arg_4.fields[0].Members, !isEmpty(members_1) && forAll((fsharpMember) => {
|
|
282
|
+
let matchResult_3, info;
|
|
283
|
+
switch (fsharpMember.tag) {
|
|
284
|
+
case 1: {
|
|
285
|
+
matchResult_3 = 0;
|
|
286
|
+
info = fsharpMember.fields[0];
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
case 2: {
|
|
290
|
+
matchResult_3 = 1;
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
default: {
|
|
294
|
+
matchResult_3 = 0;
|
|
295
|
+
info = fsharpMember.fields[0];
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
switch (matchResult_3) {
|
|
299
|
+
case 0:
|
|
300
|
+
return info.IsStatic;
|
|
301
|
+
default:
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
}, members_1))) {
|
|
305
|
+
matchResult_2 = 0;
|
|
306
|
+
members_2 = _arg_4.fields[0].Members;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
matchResult_2 = 1;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
matchResult_2 = 1;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
matchResult_2 = 1;
|
|
318
|
+
}
|
|
319
|
+
switch (matchResult_2) {
|
|
320
|
+
case 0:
|
|
321
|
+
return new FSharpType(/* TypeAlias */ 9, [new FSharpTypeAlias(empty(), fileModule.Name, empty(), new FSharpType(/* Mapped */ 7, [new FSharpMapped(concat(path, fileModule.Name, ".Exports"), empty())]), empty())]);
|
|
322
|
+
default:
|
|
323
|
+
return undefined;
|
|
324
|
+
}
|
|
325
|
+
}, fileModule.Types);
|
|
326
|
+
const nested = abbreviationsOf(concat(path, fileModule.Name, "."), fileModule.Types);
|
|
327
|
+
return toList(delay(() => append(ofArray(toArray(own)), delay(() => (!isEmpty(nested) ? singleton(new FSharpType(/* Module */ 4, [new FSharpModule(fileModule.Name, false, undefined, nested)])) : empty_1())))));
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
return empty();
|
|
331
|
+
}
|
|
332
|
+
}, types_1);
|
|
333
|
+
const abbreviations = abbreviationsOf("", types);
|
|
334
|
+
if (isEmpty(abbreviations) ? true : hasEntryExports) {
|
|
335
|
+
return empty();
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
return singleton_1(new FSharpType(/* Module */ 4, [new FSharpModule("Exports", false, undefined, abbreviations)]));
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|