@glutinum/cli 1.0.0-beta.14 → 1.0.0-beta.16

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 (34) hide show
  1. package/dist/Glutinum.Converter/GlueAST.js +19 -14
  2. package/dist/Glutinum.Converter/Merge.js +490 -206
  3. package/dist/Glutinum.Converter/Packages.js +2 -2
  4. package/dist/Glutinum.Converter/Printer.js +26 -21
  5. package/dist/Glutinum.Converter/Read.js +377 -169
  6. package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +25 -8
  7. package/dist/Glutinum.Converter/Reader/ConditionalTypeNode.js +2 -2
  8. package/dist/Glutinum.Converter/Reader/Declaration.js +15 -15
  9. package/dist/Glutinum.Converter/Reader/Deferred.js +114 -43
  10. package/dist/Glutinum.Converter/Reader/ExportAssignment.js +98 -44
  11. package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +2 -2
  12. package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +61 -46
  13. package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +31 -26
  14. package/dist/Glutinum.Converter/Reader/IntersectionTypeNode.js +38 -25
  15. package/dist/Glutinum.Converter/Reader/MappedTypeNode.js +6 -5
  16. package/dist/Glutinum.Converter/Reader/Node.js +1 -1
  17. package/dist/Glutinum.Converter/Reader/TypeNode.js +292 -30
  18. package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +1 -1
  19. package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +143 -35
  20. package/dist/Glutinum.Converter/Reader/UtilityType.js +179 -34
  21. package/dist/Glutinum.Converter/Reader/Utils.js +186 -17
  22. package/dist/Glutinum.Converter/Reader/VariableStatement.js +46 -16
  23. package/dist/Glutinum.Converter/Transform.js +1073 -638
  24. package/dist/Glutinum.Converter/Transformer/CallableProperties.js +2 -2
  25. package/dist/Glutinum.Converter/Transformer/Conditionals.js +17 -16
  26. package/dist/Glutinum.Converter/Transformer/Context.js +12 -4
  27. package/dist/Glutinum.Converter/Transformer/Exports.js +242 -66
  28. package/dist/Glutinum.Converter/Transformer/Heritage.js +449 -17
  29. package/dist/Glutinum.Converter/Transformer/KeyOfMaps.js +4 -4
  30. package/dist/Glutinum.Converter/Transformer/ParamObjectCandidate.js +105 -19
  31. package/dist/Glutinum.Converter/Transformer/TypeParameters.js +2 -2
  32. package/dist/Glutinum.Converter/Transformer/Utils.js +3 -3
  33. package/dist/Glutinum.Converter/Utils/Naming.js +10 -3
  34. package/package.json +1 -1
@@ -1,14 +1,14 @@
1
1
 
2
2
  import { substring } from "../../fable_modules/fable-library-js.5.21.0/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.21.0/List.js";
3
+ import { collect, length, contains as contains_1, filter, choose, empty, append, forAll, exists, tail, head, isEmpty, map, fold, tryPick } from "../../fable_modules/fable-library-js.5.21.0/List.js";
4
4
  import { FSharpSet__Contains, empty as empty_1, ofList, add, contains } from "../../fable_modules/fable-library-js.5.21.0/Set.js";
5
- import { safeHash, equals, comparePrimitives, curry2 } from "../../fable_modules/fable-library-js.5.21.0/Util.js";
6
- import { GluePrimitive, GlueSubstitution_substituteMember, GlueTypeUnion, GlueTypeReference, GlueType, GlueSubstitution_substitute, GlueSubstitution_ofTypeArguments, GlueMember, GlueProperty } from "../GlueAST.js";
5
+ import { Lazy, stringHash, safeHash, equals, comparePrimitives, curry2 } from "../../fable_modules/fable-library-js.5.21.0/Util.js";
6
+ import { GluePrimitive, GlueAccessor, GlueFunctionType, GlueTypeParameter, GlueSubstitution_substituteMember, GlueTypeUnion, GlueTypeReference, GlueType, GlueSubstitution_substitute, GlueSubstitution_ofTypeArguments, GlueMember, GlueProperty } from "../GlueAST.js";
7
7
  import { List_distinct, List_distinctBy } from "../../fable_modules/fable-library-js.5.21.0/Seq2.js";
8
8
  import { FSharpChoice$2 } from "../../fable_modules/fable-library-js.5.21.0/Choice.js";
9
- import { isUnionCaseName } from "./Utils.js";
10
9
  import { memberTypeParameterNames } from "./TypeParameters.js";
11
10
  import { defaultArg } from "../../fable_modules/fable-library-js.5.21.0/Option.js";
11
+ import { isUnionCaseName } from "./Utils.js";
12
12
 
13
13
  function containerOf(fullName) {
14
14
  let unquoted;
@@ -241,7 +241,7 @@ export function tryResolveMembers(typeMemory, info) {
241
241
  innerType_1 = glueType_3.fields[0];
242
242
  break;
243
243
  }
244
- case 30: {
244
+ case 31: {
245
245
  matchResult_4 = 2;
246
246
  innerType_1 = glueType_3.fields[0];
247
247
  break;
@@ -381,27 +381,88 @@ export function tryResolveMembers(typeMemory, info) {
381
381
  }), info);
382
382
  }
383
383
 
384
+ export function methodAsProperty(glueMember) {
385
+ let matchResult, info_1, glueMember_1;
386
+ if (glueMember.tag === 6) {
387
+ if (isEmpty(glueMember.fields[0].TypeParameters)) {
388
+ matchResult = 0;
389
+ info_1 = glueMember.fields[0];
390
+ }
391
+ else {
392
+ matchResult = 1;
393
+ glueMember_1 = glueMember;
394
+ }
395
+ }
396
+ else {
397
+ matchResult = 1;
398
+ glueMember_1 = glueMember;
399
+ }
400
+ switch (matchResult) {
401
+ case 0:
402
+ return new GlueMember(/* Property */ 1, [new GlueProperty(info_1.Name, info_1.Documentation, new GlueType(/* FunctionType */ 15, [new GlueFunctionType(empty(), info_1.Type, map((name) => (new GlueTypeParameter(name, undefined, undefined)), List_distinct(memberTypeParameterNames(glueMember), {
403
+ Equals: (x, y) => (x === y),
404
+ GetHashCode: (x) => (stringHash(x) | 0),
405
+ })), empty(), info_1.Parameters)]), false, info_1.IsOptional, GlueAccessor.ReadWrite, false)]);
406
+ default:
407
+ return glueMember_1;
408
+ }
409
+ }
410
+
384
411
  export function isCandidate(typeMemory, info) {
385
412
  const members = tryResolveMembers(typeMemory, info);
413
+ const inherits = (heritageClauses) => exists((_arg) => {
414
+ if (_arg.tag === 13) {
415
+ return _arg.fields[0].FullName === info.FullName;
416
+ }
417
+ else {
418
+ return false;
419
+ }
420
+ }, heritageClauses);
421
+ const isPlatformObject = new Lazy(() => (exists((_arg_1) => {
422
+ switch (_arg_1.tag) {
423
+ case 2:
424
+ return _arg_1.fields[0].Name === info.Name;
425
+ case 12: {
426
+ const classInfo = _arg_1.fields[0];
427
+ if (classInfo.Name === info.Name) {
428
+ return true;
429
+ }
430
+ else {
431
+ return inherits(classInfo.HeritageClauses);
432
+ }
433
+ }
434
+ case 1:
435
+ return inherits(_arg_1.fields[0].HeritageClauses);
436
+ default:
437
+ return false;
438
+ }
439
+ }, typeMemory) ? true : exists((_arg_2) => {
440
+ if (_arg_2.tag === 1) {
441
+ return !equals(_arg_2.fields[0].Accessor, GlueAccessor.ReadWrite);
442
+ }
443
+ else {
444
+ return false;
445
+ }
446
+ }, defaultArg(members, info.Members))));
386
447
  let hasOnlyProperties;
387
448
  if (members == null) {
388
449
  hasOnlyProperties = false;
389
450
  }
390
451
  else {
391
- const members_1 = members;
392
- hasOnlyProperties = (exists((_arg) => {
393
- if (_arg.tag === 1) {
452
+ const members_2 = members;
453
+ hasOnlyProperties = (exists((_arg_4) => {
454
+ if (_arg_4.tag === 1) {
394
455
  return true;
395
456
  }
396
457
  else {
397
458
  return false;
398
459
  }
399
- }, members_1) && forAll((_arg_1) => {
400
- switch (_arg_1.tag) {
460
+ }, members_2) && forAll((_arg_5) => {
461
+ switch (_arg_5.tag) {
401
462
  case 1:
402
- return !isUnionCaseName(_arg_1.fields[0].Name);
463
+ return !isUnionCaseName(_arg_5.fields[0].Name);
403
464
  case 5: {
404
- const indexSignature = _arg_1.fields[0];
465
+ const indexSignature = _arg_5.fields[0];
405
466
  if (!indexSignature.IsReadOnly) {
406
467
  return forAll((parameter) => equals(parameter.Type, new GlueType(/* Primitive */ 3, [GluePrimitive.String$])), indexSignature.Parameters);
407
468
  }
@@ -409,14 +470,39 @@ export function isCandidate(typeMemory, info) {
409
470
  return false;
410
471
  }
411
472
  }
473
+ case 6: {
474
+ const info_1 = _arg_5.fields[0];
475
+ if (!isUnionCaseName(info_1.Name)) {
476
+ const signature = info_1;
477
+ if ((((!isPlatformObject.Value && contains_1(new GlueMember(/* MethodSignature */ 6, [signature]), info.Members, {
478
+ Equals: equals,
479
+ GetHashCode: (x) => (safeHash(x) | 0),
480
+ })) && isEmpty(signature.TypeParameters)) && !signature.Name.startsWith("[")) && !(signature.Type.tag === 17)) {
481
+ return length(filter((_arg_3) => {
482
+ if (_arg_3.tag === 6) {
483
+ return _arg_3.fields[0].Name === signature.Name;
484
+ }
485
+ else {
486
+ return false;
487
+ }
488
+ }, members_2)) === 1;
489
+ }
490
+ else {
491
+ return false;
492
+ }
493
+ }
494
+ else {
495
+ return false;
496
+ }
497
+ }
412
498
  default:
413
499
  return false;
414
500
  }
415
- }, members_1));
501
+ }, members_2));
416
502
  }
417
503
  let typeParametersAreInferable;
418
504
  const mentioned = ofList(collect(memberTypeParameterNames, defaultArg(members, info.Members)), {
419
- Compare: (x, y) => (comparePrimitives(x, y) | 0),
505
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
420
506
  });
421
507
  typeParametersAreInferable = forAll((typeParameter) => {
422
508
  if (FSharpSet__Contains(mentioned, typeParameter.Name)) {
@@ -426,12 +512,12 @@ export function isCandidate(typeMemory, info) {
426
512
  return typeParameter.Default != null;
427
513
  }
428
514
  }, info.TypeParameters);
429
- const isDeclaredOnce = length(List_distinct(choose((_arg_2) => {
515
+ const isDeclaredOnce = length(List_distinct(choose((_arg_6) => {
430
516
  let matchResult, candidate_1;
431
- if (_arg_2.tag === 1) {
432
- if (_arg_2.fields[0].FullName === info.FullName) {
517
+ if (_arg_6.tag === 1) {
518
+ if (_arg_6.fields[0].FullName === info.FullName) {
433
519
  matchResult = 0;
434
- candidate_1 = _arg_2.fields[0];
520
+ candidate_1 = _arg_6.fields[0];
435
521
  }
436
522
  else {
437
523
  matchResult = 1;
@@ -448,7 +534,7 @@ export function isCandidate(typeMemory, info) {
448
534
  }
449
535
  }, typeMemory), {
450
536
  Equals: equals,
451
- GetHashCode: (x_1) => (safeHash(x_1) | 0),
537
+ GetHashCode: (x_2) => (safeHash(x_2) | 0),
452
538
  })) <= 1;
453
539
  if (hasOnlyProperties && typeParametersAreInferable) {
454
540
  return isDeclaredOnce;
@@ -48,7 +48,7 @@ export function typeParameterNames(glueType_mut) {
48
48
  glueType_2 = glueType.fields[0];
49
49
  break;
50
50
  }
51
- case 30: {
51
+ case 31: {
52
52
  matchResult = 2;
53
53
  glueType_2 = glueType.fields[0];
54
54
  break;
@@ -194,7 +194,7 @@ export function mentionsTypeParameter(name, glueType) {
194
194
  glueType_2 = glueType.fields[0];
195
195
  break;
196
196
  }
197
- case 30: {
197
+ case 31: {
198
198
  matchResult = 3;
199
199
  glueType_2 = glueType.fields[0];
200
200
  break;
@@ -8,7 +8,7 @@ import { concat } from "../../fable_modules/fable-library-js.5.21.0/String.js";
8
8
  import { empty as empty_1, singleton, append, delay, toList } from "../../fable_modules/fable-library-js.5.21.0/Seq.js";
9
9
  import { toArray } from "../../fable_modules/fable-library-js.5.21.0/Option.js";
10
10
 
11
- export const typedArrayNames = ofSeq(["Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array"], {
11
+ export const typedArrayNames = ofSeq(["Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array", "DataView", "ArrayBufferView"], {
12
12
  Compare: (x, y) => (comparePrimitives(x, y) | 0),
13
13
  });
14
14
 
@@ -155,8 +155,8 @@ export function replaceSelfReference(name, glueType) {
155
155
  return new GlueType(/* Union */ 7, [new GlueTypeUnion(map(replace, glueType.fields[0].fields[0]))]);
156
156
  case 14:
157
157
  return new GlueType(/* Array */ 14, [replace(glueType.fields[0])]);
158
- case 30:
159
- return new GlueType(/* ReadOnly */ 30, [replace(glueType.fields[0])]);
158
+ case 31:
159
+ return new GlueType(/* ReadOnly */ 31, [replace(glueType.fields[0])]);
160
160
  case 23:
161
161
  return new GlueType(/* OptionalType */ 23, [replace(glueType.fields[0])]);
162
162
  case 18:
@@ -1,9 +1,10 @@
1
1
 
2
2
  import { isLetterOrDigit, isDigit } from "../../fable_modules/fable-library-js.5.21.0/Char.js";
3
- import { exists } from "../../fable_modules/fable-library-js.5.21.0/Seq.js";
3
+ import { forAll, exists } from "../../fable_modules/fable-library-js.5.21.0/Seq.js";
4
4
  import { FSharpSet__Contains } from "../../fable_modules/fable-library-js.5.21.0/Set.js";
5
5
  import { fsharp } from "./Keywords.js";
6
6
  import { isNullOrWhiteSpace, replace, substring, isNullOrEmpty, concat } from "../../fable_modules/fable-library-js.5.21.0/String.js";
7
+ import { replace as replace_1 } from "../../fable_modules/fable-library-js.5.21.0/RegExp.js";
7
8
  import { Record } from "../../fable_modules/fable-library-js.5.21.0/Types.js";
8
9
  import { record_type, bool_type, string_type } from "../../fable_modules/fable-library-js.5.21.0/Reflection.js";
9
10
 
@@ -96,7 +97,7 @@ function replacePlus(text) {
96
97
  }
97
98
 
98
99
  function replaceDollar(text) {
99
- return replace(text, "$", "_DOLLAR_");
100
+ return replace(replace_1(text, "(?<=\\w)\\$(\\d+)$", "_$1"), "$", "_DOLLAR_");
100
101
  }
101
102
 
102
103
  function replaceForwardSlash(text) {
@@ -148,7 +149,13 @@ export function sanitizeTypeNameWithResult(name) {
148
149
  * A type parameter is printed after `'`, it cannot be escaped with double backticks
149
150
  */
150
151
  export function sanitizeTypeParameterName(name) {
151
- return replaceForwardSlash(replaceDollar(name));
152
+ const name_1 = replaceForwardSlash(replaceDollar(name));
153
+ if ((name_1 !== "") && forAll((character) => (character === "_"), name_1.split(""))) {
154
+ return "T" + name_1;
155
+ }
156
+ else {
157
+ return name_1;
158
+ }
152
159
  }
153
160
 
154
161
  export function sanitizeName(name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glutinum/cli",
3
- "version": "1.0.0-beta.14",
3
+ "version": "1.0.0-beta.16",
4
4
  "description": "TypeScript definition to F# bindings converter",
5
5
  "type": "module",
6
6
  "main": "index.js",