@glutinum/cli 1.0.0-beta.2 → 1.0.0-beta.4

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 (47) hide show
  1. package/README.md +16 -0
  2. package/dist/Glutinum.Converter/Abbreviations.js +9 -32
  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 +116 -65
  6. package/dist/Glutinum.Converter/Generate.js +34 -21
  7. package/dist/Glutinum.Converter/GlueAST.js +79 -41
  8. package/dist/Glutinum.Converter/Hosting.js +132 -157
  9. package/dist/Glutinum.Converter/Merge.js +369 -337
  10. package/dist/Glutinum.Converter/Packages.js +391 -92
  11. package/dist/Glutinum.Converter/Printer.js +404 -424
  12. package/dist/Glutinum.Converter/Read.js +387 -88
  13. package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +4 -4
  14. package/dist/Glutinum.Converter/Reader/Declaration.js +6 -12
  15. package/dist/Glutinum.Converter/Reader/Documentation.js +23 -35
  16. package/dist/Glutinum.Converter/Reader/ExportAssignment.js +103 -36
  17. package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +21 -36
  18. package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +26 -13
  19. package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +15 -21
  20. package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +45 -2
  21. package/dist/Glutinum.Converter/Reader/Node.js +8 -11
  22. package/dist/Glutinum.Converter/Reader/Parameters.js +34 -26
  23. package/dist/Glutinum.Converter/Reader/TypeNode.js +1988 -1343
  24. package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +32 -44
  25. package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +14 -37
  26. package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +23 -5
  27. package/dist/Glutinum.Converter/Reader/Types.js +290 -15
  28. package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +14 -28
  29. package/dist/Glutinum.Converter/Reader/Utils.js +343 -28
  30. package/dist/Glutinum.Converter/Reader/VariableStatement.js +2 -3
  31. package/dist/Glutinum.Converter/Transform.js +3619 -8456
  32. package/dist/Glutinum.Converter/Transformer/AnyFunctionOverloads.js +116 -0
  33. package/dist/Glutinum.Converter/Transformer/CallableProperties.js +454 -0
  34. package/dist/Glutinum.Converter/Transformer/Comment.js +136 -0
  35. package/dist/Glutinum.Converter/Transformer/Conditionals.js +1149 -0
  36. package/dist/Glutinum.Converter/Transformer/Context.js +664 -0
  37. package/dist/Glutinum.Converter/Transformer/Enum.js +80 -0
  38. package/dist/Glutinum.Converter/Transformer/Heritage.js +406 -0
  39. package/dist/Glutinum.Converter/Transformer/KeyOfMaps.js +488 -0
  40. package/dist/Glutinum.Converter/Transformer/ParamObjectCandidate.js +460 -0
  41. package/dist/Glutinum.Converter/Transformer/TypeParameters.js +448 -0
  42. package/dist/Glutinum.Converter/Transformer/UnionOverloads.js +353 -0
  43. package/dist/Glutinum.Converter/Transformer/Utils.js +341 -0
  44. package/dist/Glutinum.Converter/TypeScript.Extensions.js +0 -10
  45. package/dist/Glutinum.Converter/Utils/String.js +14 -3
  46. package/dist/Program.js +18 -10
  47. package/package.json +1 -1
@@ -0,0 +1,460 @@
1
+
2
+ import { substring } from "../../fable_modules/fable-library-js.5.17.2/String.js";
3
+ import { length, collect, filter, choose, empty, append, forAll, exists, tail, head, isEmpty, map, fold, tryPick } from "../../fable_modules/fable-library-js.5.17.2/List.js";
4
+ import { FSharpSet__Contains, empty as empty_1, ofList, add, contains } from "../../fable_modules/fable-library-js.5.17.2/Set.js";
5
+ import { safeHash, equals, comparePrimitives, curry2 } from "../../fable_modules/fable-library-js.5.17.2/Util.js";
6
+ import { GluePrimitive, GlueSubstitution_substituteMember, GlueTypeUnion, GlueTypeReference, GlueType, GlueSubstitution_substitute, GlueSubstitution_ofTypeArguments, GlueMember, GlueProperty } from "../GlueAST.js";
7
+ import { List_distinct, List_distinctBy } from "../../fable_modules/fable-library-js.5.17.2/Seq2.js";
8
+ import { FSharpChoice$2 } from "../../fable_modules/fable-library-js.5.17.2/Choice.js";
9
+ import { isUnionCaseName } from "./Utils.js";
10
+ import { memberTypeParameterNames } from "./TypeParameters.js";
11
+ import { defaultArg } from "../../fable_modules/fable-library-js.5.17.2/Option.js";
12
+
13
+ function containerOf(fullName) {
14
+ let unquoted;
15
+ if (fullName.startsWith("\"")) {
16
+ const matchValue = fullName.indexOf("\".", 1) | 0;
17
+ unquoted = ((matchValue === -1) ? fullName : substring(fullName, matchValue + 2));
18
+ }
19
+ else {
20
+ unquoted = fullName;
21
+ }
22
+ const matchValue_1 = unquoted.lastIndexOf(".") | 0;
23
+ if (matchValue_1 === -1) {
24
+ return "";
25
+ }
26
+ else {
27
+ return substring(unquoted, 0, matchValue_1);
28
+ }
29
+ }
30
+
31
+ function isEnclosing(container, inner) {
32
+ if ((container === "") ? true : (container === inner)) {
33
+ return true;
34
+ }
35
+ else {
36
+ return inner.startsWith(container + ".");
37
+ }
38
+ }
39
+
40
+ export function tryResolveMembers(typeMemory, info) {
41
+ const tryFindInterface = (fullName) => tryPick((_arg) => {
42
+ let matchResult, candidate_1;
43
+ if (_arg.tag === 1) {
44
+ if (_arg.fields[0].FullName === fullName) {
45
+ matchResult = 0;
46
+ candidate_1 = _arg.fields[0];
47
+ }
48
+ else {
49
+ matchResult = 1;
50
+ }
51
+ }
52
+ else {
53
+ matchResult = 1;
54
+ }
55
+ switch (matchResult) {
56
+ case 0:
57
+ return candidate_1;
58
+ default:
59
+ return undefined;
60
+ }
61
+ }, typeMemory);
62
+ const resolve = (visited, info_1) => {
63
+ let inheritedMembers, ownNames;
64
+ if (contains(info_1.FullName, visited)) {
65
+ return undefined;
66
+ }
67
+ else {
68
+ const visited_1 = add(info_1.FullName, visited);
69
+ const option_9 = fold((acc, heritageClause_1) => {
70
+ let typeReference;
71
+ let matchValue_3;
72
+ const heritageClause = heritageClause_1;
73
+ let matchResult_1, typeReference_1, members, typeReference_2;
74
+ switch (heritageClause.tag) {
75
+ case 13: {
76
+ if ((typeReference = heritageClause.fields[0], typeReference.IsStandardLibrary && (typeReference.Name === "Partial"))) {
77
+ matchResult_1 = 0;
78
+ typeReference_1 = heritageClause.fields[0];
79
+ }
80
+ else {
81
+ matchResult_1 = 2;
82
+ typeReference_2 = heritageClause.fields[0];
83
+ }
84
+ break;
85
+ }
86
+ case 27: {
87
+ switch (heritageClause.fields[0].tag) {
88
+ case 4: {
89
+ matchResult_1 = 1;
90
+ members = heritageClause.fields[0].fields[0];
91
+ break;
92
+ }
93
+ case 5: {
94
+ matchResult_1 = 1;
95
+ members = heritageClause.fields[0].fields[0];
96
+ break;
97
+ }
98
+ default:
99
+ matchResult_1 = 3;
100
+ }
101
+ break;
102
+ }
103
+ default:
104
+ matchResult_1 = 3;
105
+ }
106
+ switch (matchResult_1) {
107
+ case 0: {
108
+ const matchValue = typeReference_1.TypeArguments;
109
+ let matchResult_2, baseReference;
110
+ if (!isEmpty(matchValue)) {
111
+ if (head(matchValue).tag === 13) {
112
+ if (isEmpty(tail(matchValue))) {
113
+ matchResult_2 = 0;
114
+ baseReference = head(matchValue).fields[0];
115
+ }
116
+ else {
117
+ matchResult_2 = 1;
118
+ }
119
+ }
120
+ else {
121
+ matchResult_2 = 1;
122
+ }
123
+ }
124
+ else {
125
+ matchResult_2 = 1;
126
+ }
127
+ switch (matchResult_2) {
128
+ case 0: {
129
+ let option_3;
130
+ const option = tryFindInterface(baseReference.FullName);
131
+ const binder = curry2(resolve)(visited_1);
132
+ const option_1 = option;
133
+ option_3 = ((option_1 != null) ? binder(option_1) : undefined);
134
+ matchValue_3 = ((option_3 != null) ? map((_arg_1) => {
135
+ if (_arg_1.tag === 1) {
136
+ const property = _arg_1.fields[0];
137
+ return new GlueMember(/* Property */ 1, [new GlueProperty(property.Name, property.Documentation, property.Type, property.IsStatic, true, property.Accessor, property.IsPrivate)]);
138
+ }
139
+ else {
140
+ return _arg_1;
141
+ }
142
+ }, option_3) : undefined);
143
+ break;
144
+ }
145
+ default:
146
+ matchValue_3 = undefined;
147
+ }
148
+ break;
149
+ }
150
+ case 1: {
151
+ matchValue_3 = members;
152
+ break;
153
+ }
154
+ case 2: {
155
+ const matchValue_1 = tryFindInterface(typeReference_2.FullName);
156
+ if (matchValue_1 == null) {
157
+ matchValue_3 = undefined;
158
+ }
159
+ else {
160
+ const baseInterface = matchValue_1;
161
+ const substitutions = GlueSubstitution_ofTypeArguments(baseInterface.TypeParameters, typeReference_2.TypeArguments);
162
+ const qualifySelf = (glueType) => {
163
+ let reference;
164
+ let matchResult_3, thisType_1, reference_1, reference_2, cases, elementType, innerType, glueType_2;
165
+ switch (glueType.tag) {
166
+ case 17: {
167
+ if (glueType.fields[0].Name === baseInterface.Name) {
168
+ matchResult_3 = 0;
169
+ thisType_1 = glueType.fields[0];
170
+ }
171
+ else {
172
+ matchResult_3 = 6;
173
+ glueType_2 = glueType;
174
+ }
175
+ break;
176
+ }
177
+ case 13: {
178
+ if ((reference = glueType.fields[0], (reference.FullName === baseInterface.FullName) && isEmpty(reference.ModulePath))) {
179
+ matchResult_3 = 1;
180
+ reference_1 = glueType.fields[0];
181
+ }
182
+ else {
183
+ matchResult_3 = 2;
184
+ reference_2 = glueType.fields[0];
185
+ }
186
+ break;
187
+ }
188
+ case 7: {
189
+ matchResult_3 = 3;
190
+ cases = glueType.fields[0].fields[0];
191
+ break;
192
+ }
193
+ case 14: {
194
+ matchResult_3 = 4;
195
+ elementType = glueType.fields[0];
196
+ break;
197
+ }
198
+ case 23: {
199
+ matchResult_3 = 5;
200
+ innerType = glueType.fields[0];
201
+ break;
202
+ }
203
+ default: {
204
+ matchResult_3 = 6;
205
+ glueType_2 = glueType;
206
+ }
207
+ }
208
+ switch (matchResult_3) {
209
+ case 0:
210
+ return new GlueType(/* TypeReference */ 13, [new GlueTypeReference(baseInterface.Name, baseInterface.FullName, typeReference_2.ModulePath, map((typeParameter) => GlueSubstitution_substitute(substitutions, new GlueType(/* TypeParameter */ 16, [typeParameter.Name])), thisType_1.TypeParameters), false)]);
211
+ case 1:
212
+ return new GlueType(/* TypeReference */ 13, [new GlueTypeReference(reference_1.Name, reference_1.FullName, typeReference_2.ModulePath, map(qualifySelf, reference_1.TypeArguments), reference_1.IsStandardLibrary)]);
213
+ case 2:
214
+ return new GlueType(/* TypeReference */ 13, [new GlueTypeReference(reference_2.Name, reference_2.FullName, reference_2.ModulePath, map(qualifySelf, reference_2.TypeArguments), reference_2.IsStandardLibrary)]);
215
+ case 3:
216
+ return new GlueType(/* Union */ 7, [new GlueTypeUnion(map(qualifySelf, cases))]);
217
+ case 4:
218
+ return new GlueType(/* Array */ 14, [qualifySelf(elementType)]);
219
+ case 5:
220
+ return new GlueType(/* OptionalType */ 23, [qualifySelf(innerType)]);
221
+ default:
222
+ return glueType_2;
223
+ }
224
+ };
225
+ const namesForeignType = (glueType_3_mut) => {
226
+ namesForeignType:
227
+ while (true) {
228
+ const glueType_3 = glueType_3_mut;
229
+ let matchResult_4, innerType_1;
230
+ switch (glueType_3.tag) {
231
+ case 13: {
232
+ matchResult_4 = 0;
233
+ break;
234
+ }
235
+ case 7: {
236
+ matchResult_4 = 1;
237
+ break;
238
+ }
239
+ case 14: {
240
+ matchResult_4 = 2;
241
+ innerType_1 = glueType_3.fields[0];
242
+ break;
243
+ }
244
+ case 30: {
245
+ matchResult_4 = 2;
246
+ innerType_1 = glueType_3.fields[0];
247
+ break;
248
+ }
249
+ case 23: {
250
+ matchResult_4 = 2;
251
+ innerType_1 = glueType_3.fields[0];
252
+ break;
253
+ }
254
+ case 18: {
255
+ matchResult_4 = 3;
256
+ break;
257
+ }
258
+ case 15: {
259
+ matchResult_4 = 4;
260
+ break;
261
+ }
262
+ default:
263
+ matchResult_4 = 5;
264
+ }
265
+ switch (matchResult_4) {
266
+ case 0: {
267
+ const reference_3 = glueType_3.fields[0];
268
+ if ((isEmpty(reference_3.ModulePath) && !reference_3.IsStandardLibrary) && !isEnclosing(containerOf(reference_3.FullName), containerOf(info_1.FullName))) {
269
+ return true;
270
+ }
271
+ else {
272
+ return exists(namesForeignType, reference_3.TypeArguments);
273
+ }
274
+ }
275
+ case 1:
276
+ return exists(namesForeignType, glueType_3.fields[0].fields[0]);
277
+ case 2: {
278
+ glueType_3_mut = innerType_1;
279
+ continue namesForeignType;
280
+ }
281
+ case 3:
282
+ return exists(namesForeignType, glueType_3.fields[0]);
283
+ case 4: {
284
+ const functionType = glueType_3.fields[0];
285
+ if (namesForeignType(functionType.Type)) {
286
+ return true;
287
+ }
288
+ else {
289
+ return exists((parameter) => namesForeignType(parameter.Type), functionType.Parameters);
290
+ }
291
+ }
292
+ default:
293
+ return false;
294
+ }
295
+ break;
296
+ }
297
+ };
298
+ let option_7;
299
+ const option_5 = resolve(visited_1, baseInterface);
300
+ option_7 = ((option_5 != null) ? map((glueMember_1) => {
301
+ const matchValue_2 = GlueSubstitution_substituteMember(substitutions, glueMember_1);
302
+ if (matchValue_2.tag === 1) {
303
+ const property_1 = matchValue_2.fields[0];
304
+ return new GlueMember(/* Property */ 1, [new GlueProperty(property_1.Name, property_1.Documentation, qualifySelf(property_1.Type), property_1.IsStatic, property_1.IsOptional, property_1.Accessor, property_1.IsPrivate)]);
305
+ }
306
+ else {
307
+ return matchValue_2;
308
+ }
309
+ }, option_5) : undefined);
310
+ matchValue_3 = ((option_7 != null) ? (forAll((_arg_2) => {
311
+ if (_arg_2.tag === 1) {
312
+ return !namesForeignType(_arg_2.fields[0].Type);
313
+ }
314
+ else {
315
+ return true;
316
+ }
317
+ }, option_7) ? option_7 : undefined) : undefined);
318
+ }
319
+ break;
320
+ }
321
+ default:
322
+ matchValue_3 = undefined;
323
+ }
324
+ let matchResult_5, acc_1, members_1;
325
+ if (acc != null) {
326
+ if (matchValue_3 != null) {
327
+ matchResult_5 = 0;
328
+ acc_1 = acc;
329
+ members_1 = matchValue_3;
330
+ }
331
+ else {
332
+ matchResult_5 = 1;
333
+ }
334
+ }
335
+ else {
336
+ matchResult_5 = 1;
337
+ }
338
+ switch (matchResult_5) {
339
+ case 0:
340
+ return append(acc_1, members_1);
341
+ default:
342
+ return undefined;
343
+ }
344
+ }, empty(), info_1.HeritageClauses);
345
+ if (option_9 != null) {
346
+ return (inheritedMembers = option_9, (ownNames = ofList(choose((_arg_3) => {
347
+ if (_arg_3.tag === 1) {
348
+ return _arg_3.fields[0].Name;
349
+ }
350
+ else {
351
+ return undefined;
352
+ }
353
+ }, info_1.Members), {
354
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
355
+ }), append(List_distinctBy((_arg_5) => {
356
+ if (_arg_5.tag === 1) {
357
+ return new FSharpChoice$2(/* Choice1Of2 */ 0, [_arg_5.fields[0].Name]);
358
+ }
359
+ else {
360
+ return new FSharpChoice$2(/* Choice2Of2 */ 1, [_arg_5]);
361
+ }
362
+ }, filter((_arg_4) => {
363
+ if (_arg_4.tag === 1) {
364
+ return !contains(_arg_4.fields[0].Name, ownNames);
365
+ }
366
+ else {
367
+ return true;
368
+ }
369
+ }, inheritedMembers), {
370
+ Equals: equals,
371
+ GetHashCode: (x_1) => (safeHash(x_1) | 0),
372
+ }), info_1.Members)));
373
+ }
374
+ else {
375
+ return undefined;
376
+ }
377
+ }
378
+ };
379
+ return resolve(empty_1({
380
+ Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
381
+ }), info);
382
+ }
383
+
384
+ export function isCandidate(typeMemory, info) {
385
+ const members = tryResolveMembers(typeMemory, info);
386
+ let hasOnlyProperties;
387
+ if (members == null) {
388
+ hasOnlyProperties = false;
389
+ }
390
+ else {
391
+ const members_1 = members;
392
+ hasOnlyProperties = (exists((_arg) => {
393
+ if (_arg.tag === 1) {
394
+ return true;
395
+ }
396
+ else {
397
+ return false;
398
+ }
399
+ }, members_1) && forAll((_arg_1) => {
400
+ switch (_arg_1.tag) {
401
+ case 1:
402
+ return !isUnionCaseName(_arg_1.fields[0].Name);
403
+ case 5: {
404
+ const indexSignature = _arg_1.fields[0];
405
+ if (!indexSignature.IsReadOnly) {
406
+ return forAll((parameter) => equals(parameter.Type, new GlueType(/* Primitive */ 3, [GluePrimitive.String$])), indexSignature.Parameters);
407
+ }
408
+ else {
409
+ return false;
410
+ }
411
+ }
412
+ default:
413
+ return false;
414
+ }
415
+ }, members_1));
416
+ }
417
+ let typeParametersAreInferable;
418
+ const mentioned = ofList(collect(memberTypeParameterNames, defaultArg(members, info.Members)), {
419
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
420
+ });
421
+ typeParametersAreInferable = forAll((typeParameter) => {
422
+ if (FSharpSet__Contains(mentioned, typeParameter.Name)) {
423
+ return true;
424
+ }
425
+ else {
426
+ return typeParameter.Default != null;
427
+ }
428
+ }, info.TypeParameters);
429
+ const isDeclaredOnce = length(List_distinct(choose((_arg_2) => {
430
+ let matchResult, candidate_1;
431
+ if (_arg_2.tag === 1) {
432
+ if (_arg_2.fields[0].FullName === info.FullName) {
433
+ matchResult = 0;
434
+ candidate_1 = _arg_2.fields[0];
435
+ }
436
+ else {
437
+ matchResult = 1;
438
+ }
439
+ }
440
+ else {
441
+ matchResult = 1;
442
+ }
443
+ switch (matchResult) {
444
+ case 0:
445
+ return candidate_1;
446
+ default:
447
+ return undefined;
448
+ }
449
+ }, typeMemory), {
450
+ Equals: equals,
451
+ GetHashCode: (x_1) => (safeHash(x_1) | 0),
452
+ })) <= 1;
453
+ if (hasOnlyProperties && typeParametersAreInferable) {
454
+ return isDeclaredOnce;
455
+ }
456
+ else {
457
+ return false;
458
+ }
459
+ }
460
+