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

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.
@@ -136,7 +136,7 @@ function eraseType(bound, typ) {
136
136
  default:
137
137
  return _arg_1;
138
138
  }
139
- }, unionInfo.Cases), unionInfo.IsOptional, unionInfo.TypeParameters, unionInfo.Constants)]);
139
+ }, unionInfo.Cases), unionInfo.IsOptional, unionInfo.TypeParameters, unionInfo.Constants, unionInfo.Conversions)]);
140
140
  }
141
141
  case 10:
142
142
  return new FSharpType(/* Function */ 16, [new FSharpFunctionType(map((parameter) => (new FSharpParameter(parameter.Attributes, parameter.Name, parameter.IsOptional, erase(parameter.Type), parameter.OriginalGlueMember)), functionType.Parameters), erase(functionType.ReturnType))]);
@@ -145,7 +145,7 @@ export function FSharpUnionConstant_$reflection() {
145
145
  }
146
146
 
147
147
  export class FSharpUnion extends Record {
148
- constructor(Attributes, Name, Cases, IsOptional, TypeParameters, Constants) {
148
+ constructor(Attributes, Name, Cases, IsOptional, TypeParameters, Constants, Conversions) {
149
149
  super();
150
150
  this.Attributes = Attributes;
151
151
  this.Name = Name;
@@ -153,11 +153,12 @@ export class FSharpUnion extends Record {
153
153
  this.IsOptional = IsOptional;
154
154
  this.TypeParameters = TypeParameters;
155
155
  this.Constants = Constants;
156
+ this.Conversions = Conversions;
156
157
  }
157
158
  }
158
159
 
159
160
  export function FSharpUnion_$reflection() {
160
- return record_type("Glutinum.Converter.FSharpAST.FSharpUnion", [], FSharpUnion, () => [["Attributes", list_type(FSharpAttribute_$reflection())], ["Name", string_type], ["Cases", list_type(FSharpUnionCase_$reflection())], ["IsOptional", bool_type], ["TypeParameters", list_type(FSharpTypeParameter_$reflection())], ["Constants", list_type(FSharpUnionConstant_$reflection())]]);
161
+ return record_type("Glutinum.Converter.FSharpAST.FSharpUnion", [], FSharpUnion, () => [["Attributes", list_type(FSharpAttribute_$reflection())], ["Name", string_type], ["Cases", list_type(FSharpUnionCase_$reflection())], ["IsOptional", bool_type], ["TypeParameters", list_type(FSharpTypeParameter_$reflection())], ["Constants", list_type(FSharpUnionConstant_$reflection())], ["Conversions", list_type(FSharpType_$reflection())]]);
161
162
  }
162
163
 
163
164
  export class FSharpModule extends Record {
@@ -661,7 +662,7 @@ export function FSharpTypeModule_mapChildren(f, typ) {
661
662
  default:
662
663
  return _arg;
663
664
  }
664
- }, unionInfo.Cases), unionInfo.IsOptional, unionInfo.TypeParameters, unionInfo.Constants)]);
665
+ }, unionInfo.Cases), unionInfo.IsOptional, unionInfo.TypeParameters, unionInfo.Constants, unionInfo.Conversions)]);
665
666
  }
666
667
  case 16: {
667
668
  const functionType = typ.fields[0];
@@ -1,7 +1,7 @@
1
1
 
2
2
  import { FSharpRef, Record } from "../fable_modules/fable-library-js.5.21.0/Types.js";
3
3
  import { record_type, tuple_type, list_type, class_type, string_type } from "../fable_modules/fable-library-js.5.21.0/Reflection.js";
4
- import { FSharpClass, FSharpModule, FSharpInterface, FSharpStaticMemberInfo, FSharpMember, FSharpMemberInfo, FSharpTypeModule_children, FSharpFunctionType, FSharpParameter, FSharpTypeModule_mapChildren, FSharpTypeReference, FSharpType, FSharpType_$reflection } from "./FsharpAST.js";
4
+ import { FSharpUnion, FSharpClass, FSharpModule, FSharpInterface, FSharpStaticMemberInfo, FSharpMember, FSharpMemberInfo, FSharpTypeModule_children, FSharpFunctionType, FSharpParameter, FSharpTypeModule_mapChildren, FSharpTypeReference, FSharpType, FSharpType_$reflection } from "./FsharpAST.js";
5
5
  import { ofList, FSharpMap__TryFind, tryFind, ofSeq, empty } from "../fable_modules/fable-library-js.5.21.0/Map.js";
6
6
  import { Exception, safeHash, equals, compare, compareArrays, arrayHash, equalArrays, defaultOf, int32ToString, disposeSafe, getEnumerator, comparePrimitives } from "../fable_modules/fable-library-js.5.21.0/Util.js";
7
7
  import { mapIndexed, tryFindIndex, ofSeq as ofSeq_2, maxBy, skip, take, forAll2, ofArray, indexed, sortBy, exists, forAll, filter, collect, head, tail, zip, empty as empty_1, length, map, choose, singleton, append, isEmpty as isEmpty_1 } from "../fable_modules/fable-library-js.5.21.0/List.js";
@@ -955,25 +955,45 @@ export function disambiguateOverloads(aliases, types) {
955
955
  }, types);
956
956
  }
957
957
 
958
- /**
959
- * If a type is declared twice, merge them into one.
960
- *
961
- * This can happens because TypeScript allows multiple declarations of the same type.
962
- *
963
- * Example:
964
- *
965
- * <code lang="typescript">
966
- * interface A {
967
- * a: string;
968
- * }
969
- *
970
- * interface A {
971
- * b: number;
972
- * }
973
- * </code>
974
- */
958
+ function withoutParameterNames(typ) {
959
+ if (typ.tag === 16) {
960
+ const functionType = typ.fields[0];
961
+ return new FSharpType(/* Function */ 16, [new FSharpFunctionType(map((parameter) => (new FSharpParameter(parameter.Attributes, "", parameter.IsOptional, withoutParameterNames(parameter.Type), parameter.OriginalGlueMember)), functionType.Parameters), withoutParameterNames(functionType.ReturnType))]);
962
+ }
963
+ else {
964
+ return FSharpTypeModule_mapChildren(withoutParameterNames, typ);
965
+ }
966
+ }
967
+
968
+ function unionConversions(aliases, types) {
969
+ return map((typ) => {
970
+ switch (typ.tag) {
971
+ case 1: {
972
+ const unionInfo = typ.fields[0];
973
+ return new FSharpType(/* Union */ 1, [new FSharpUnion(unionInfo.Attributes, unionInfo.Name, unionInfo.Cases, unionInfo.IsOptional, unionInfo.TypeParameters, unionInfo.Constants, List_distinctBy((arg) => withoutParameterNames(signatureType(aliases, arg)), choose((_arg) => {
974
+ if (_arg.tag === 2) {
975
+ return _arg.fields[1];
976
+ }
977
+ else {
978
+ return undefined;
979
+ }
980
+ }, unionInfo.Cases), {
981
+ Equals: equals,
982
+ GetHashCode: (x) => (safeHash(x) | 0),
983
+ }))]);
984
+ }
985
+ case 4: {
986
+ const moduleInfo = typ.fields[0];
987
+ return new FSharpType(/* Module */ 4, [new FSharpModule(moduleInfo.Name, moduleInfo.IsRecursive, moduleInfo.ImportSpecifier, unionConversions(aliases, moduleInfo.Types))]);
988
+ }
989
+ default:
990
+ return typ;
991
+ }
992
+ }, types);
993
+ }
994
+
975
995
  export function applyWith(aliases, types) {
976
- return distinctMembers(aliases, dropEmptyModules(mergeModules(aliases, mergeTypes(aliases, types))));
996
+ return unionConversions(aliases, distinctMembers(aliases, dropEmptyModules(mergeModules(aliases, mergeTypes(aliases, types)))));
977
997
  }
978
998
 
979
999
  export function apply(types) {
@@ -7,13 +7,12 @@ import { trimStart, interpolate, substring, join, replace, concat, isNullOrWhite
7
7
  import { splitLines, replace as replace_1, removeSingleQuote, removeDoubleQuote, capitalizeFirstLetter } from "./Utils/String.js";
8
8
  import { isDigit2 } from "../fable_modules/fable-library-js.5.21.0/Char.js";
9
9
  import { cons, mapIndexed, empty, forAll, ofArray, concat as concat_1, partition, length, singleton, append, choose, filter, iterateIndexed, iterate, isEmpty, map, exists } from "../fable_modules/fable-library-js.5.21.0/List.js";
10
- import { stringHash, disposeSafe, getEnumerator, int32ToString, Exception } from "../fable_modules/fable-library-js.5.21.0/Util.js";
10
+ import { disposeSafe, getEnumerator, int32ToString, Exception } from "../fable_modules/fable-library-js.5.21.0/Util.js";
11
11
  import { sanitizeTypeParameterName } from "./Utils/Naming.js";
12
12
  import { escape, create, isMatch, replace as replace_2 } from "../fable_modules/fable-library-js.5.21.0/RegExp.js";
13
13
  import { removeConsecutiveEmptyLines, trimEmptyLines } from "./Utils/List.js";
14
14
  import { FSharpInterface, FSharpAttribute } from "./FsharpAST.js";
15
15
  import { singleton as singleton_1, append as append_1, delay, toList } from "../fable_modules/fable-library-js.5.21.0/Seq.js";
16
- import { List_distinctBy } from "../fable_modules/fable-library-js.5.21.0/Seq2.js";
17
16
 
18
17
  export class Printer {
19
18
  constructor() {
@@ -978,7 +977,7 @@ function printUnion(printer, unionInfo) {
978
977
  }
979
978
  }, unionInfo.Attributes)) {
980
979
  const returnType = printTypeNameWithTypeParameters(unionInfo.Name, unionInfo.TypeParameters);
981
- iterate((caseType_1) => {
980
+ iterate((caseType) => {
982
981
  const enumerator = getEnumerator(["op_Implicit", "op_ErasedCast"]);
983
982
  try {
984
983
  while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
@@ -986,31 +985,26 @@ function printUnion(printer, unionInfo) {
986
985
  Printer__get_NewLine(printer);
987
986
  Printer__Write_Z721C83C5(printer, "[<Emit(\"$0\")>]");
988
987
  Printer__get_NewLine(printer);
989
- Printer__Write_Z721C83C5(printer, `static member ${name_2}(value: ${caseType_1}) : ${returnType} = nativeOnly`);
988
+ Printer__Write_Z721C83C5(printer, `static member ${name_2}(value: ${caseType}) : ${returnType} = nativeOnly`);
990
989
  Printer__get_NewLine(printer);
991
990
  }
992
991
  }
993
992
  finally {
994
993
  disposeSafe(enumerator);
995
994
  }
996
- }, List_distinctBy((caseType) => {
997
- if (caseType === "JS.Uint8ClampedArray") {
998
- return "JS.Uint8Array";
999
- }
1000
- else {
1001
- return caseType;
1002
- }
1003
- }, choose((_arg_1) => {
995
+ }, map(printType, unionInfo.Conversions));
996
+ iterate((_arg_1) => {
1004
997
  if (_arg_1.tag === 2) {
1005
- return printType(_arg_1.fields[1]);
1006
- }
1007
- else {
1008
- return undefined;
998
+ const caseName = _arg_1.fields[0];
999
+ Printer__get_NewLine(printer);
1000
+ Printer__Write_Z721C83C5(printer, concat("/// Unchecked, the value as <c>", caseName, "</c> whatever case it holds"));
1001
+ Printer__get_NewLine(printer);
1002
+ Printer__Write_Z721C83C5(printer, "[<Emit(\"$0\")>]");
1003
+ Printer__get_NewLine(printer);
1004
+ Printer__Write_Z721C83C5(printer, `member _.As${caseName}: ${printType(_arg_1.fields[1])} = nativeOnly`);
1005
+ Printer__get_NewLine(printer);
1009
1006
  }
1010
- }, unionInfo.Cases), {
1011
- Equals: (x, y) => (x === y),
1012
- GetHashCode: (x) => (stringHash(x) | 0),
1013
- }));
1007
+ }, unionInfo.Cases);
1014
1008
  }
1015
1009
  Printer__get_Unindent(printer);
1016
1010
  }
@@ -8,15 +8,16 @@ import { SealedTypeInfo, TransformDeclarationTypeParametersResult, TransformType
8
8
  import { FSharpModule, FSharpSingleErasedCaseUnion, FSharpJSApi, FSharpEnum, FSharpEnumCase, FSharpLiteral, FSharpUnionCaseNamed, FSharpClass, FSharpConstructor, FSharpExplicitField, FSharpMemberInfoBody, FSharpAccessibility, FSharpStaticMemberInfo, FSharpMember, FSharpMemberInfo, FSharpAccessor, FSharpParameter, FSharpThisType, FSharpPrimitive, FSharpTypeAlias, FSharpDelegate, FSharpFunctionType, FSharpTypeReference, FSharpUnion, FSharpUnionCase, FSharpTypeParameter, FSharpMapped, FSharpInterface, FSharpAttribute, FSharpType, FSharpType_$reflection } from "./FsharpAST.js";
9
9
  import { ofSeq as ofSeq_1, empty as empty_3, add, contains as contains_2, ofList, FSharpSet__Contains } from "../fable_modules/fable-library-js.5.21.0/Set.js";
10
10
  import { aggregatedExports, replaceSelfReference, isUnitAlias, typedArrayNames, transformPrimitive, requiredBeforeParamArray, isDataObject, Interface_makePartial, tryUnwrapOption, iteratorNames } from "./Transformer/Utils.js";
11
- import { value as value_7, toArray, defaultArg } from "../fable_modules/fable-library-js.5.21.0/Option.js";
12
- import { zip, mapFold, tryPick, item, concat as concat_1, reverse, iterate, cons, foldBack, fold, sortBy, tryFind, ofSeq, forAll, truncate, contains, exists, partition, mapIndexed, filter, append, length, collect, tryLast, choose, tryHead, singleton, empty, ofArray, map, head as head_1, tail as tail_1, isEmpty } from "../fable_modules/fable-library-js.5.21.0/List.js";
11
+ import { toArray, value as value_7, defaultArg } from "../fable_modules/fable-library-js.5.21.0/Option.js";
12
+ import { zip, mapFold, tryPick, item, concat as concat_1, reverse, iterate, cons, foldBack, fold, sortBy, tryFind, ofSeq, truncate, contains, exists, partition, mapIndexed, forAll, map2, filter, append, length, collect, tryLast, choose, tryHead, singleton, empty, ofArray, map, head as head_1, tail as tail_1, isEmpty } from "../fable_modules/fable-library-js.5.21.0/List.js";
13
13
  import { aliasArities, membersNameUndeclaredTypeParameters, mentionsTypeParameter, ownTypeParameterDefaults, typeParameterNames as typeParameterNames_2, unconstrained, memberTypeParameterNames, typeArguments, declaredTypeParameters as declaredTypeParameters_1 } from "./Transformer/TypeParameters.js";
14
14
  import { List_groupBy, List_distinct } from "../fable_modules/fable-library-js.5.21.0/Seq2.js";
15
- import { uncurry2, curry2, Lazy, structuralHash, Exception, numberHash, int32ToString, comparePrimitives, safeHash, equals, stringHash } from "../fable_modules/fable-library-js.5.21.0/Util.js";
16
- import { replace, trim, interpolate, concat } from "../fable_modules/fable-library-js.5.21.0/String.js";
15
+ import { uncurry2, curry2, Lazy, Exception, numberHash, int32ToString, comparePrimitives, safeHash, structuralHash, equals, stringHash } from "../fable_modules/fable-library-js.5.21.0/Util.js";
16
+ import { replace, interpolate, substring, trimStart, split, trim, concat } from "../fable_modules/fable-library-js.5.21.0/String.js";
17
17
  import { resolveMembers, isConditionalAlias, isInterfaceDeclaration } from "./Transformer/Conditionals.js";
18
- import { FSharpMap__TryFind, exists as exists_1, empty as empty_2, ofList as ofList_1, FSharpMap__ContainsKey, FSharpMap__get_Item, map as map_1 } from "../fable_modules/fable-library-js.5.21.0/Map.js";
18
+ import { contains as contains_1, last } from "../fable_modules/fable-library-js.5.21.0/Array.js";
19
19
  import { removeSurroundingQuotes, sanitizeTypeNameWithResult, sanitizeTypeName } from "./Utils/Naming.js";
20
+ import { FSharpMap__TryFind, exists as exists_1, empty as empty_2, ofList as ofList_1, FSharpMap__ContainsKey, FSharpMap__get_Item, map as map_1 } from "../fable_modules/fable-library-js.5.21.0/Map.js";
20
21
  import { map as map_2, append as append_1, empty as empty_1, singleton as singleton_1, delay, toList } from "../fable_modules/fable-library-js.5.21.0/Seq.js";
21
22
  import { capitalizeFirstLetter } from "./Utils/String.js";
22
23
  import { addToSet } from "../fable_modules/fable-library-js.5.21.0/MapUtil.js";
@@ -25,7 +26,6 @@ import { isMap, keysModule, isMapNamed, expandMembers as expandMembers_1 } from
25
26
  import { defaultMaxOverloads, isNullish, tryCases, expandMembers as expandMembers_2 } from "./Transformer/UnionOverloads.js";
26
27
  import { applyWith as applyWith_1, disambiguateOverloads, aliasesOf, parametersSignature, Aliases_get_Empty, distinctBySignature } from "./Merge.js";
27
28
  import { min } from "../fable_modules/fable-library-js.5.21.0/Double.js";
28
- import { contains as contains_1 } from "../fable_modules/fable-library-js.5.21.0/Array.js";
29
29
  import { inheritsIterable, asMethods, tryCallableHeritage } from "./Transformer/CallableProperties.js";
30
30
  import { withoutBaseClassProperties, withoutBasesOfBases, isInheritableType, isSelfHeritage, isArrayHeritage, isErrorHeritage, withoutRedeclaredBases } from "./Transformer/Heritage.js";
31
31
  import { isCandidate, tryResolveMembers } from "./Transformer/ParamObjectCandidate.js";
@@ -557,7 +557,7 @@ function UtilityType_readonlyUnion(context, interfaces) {
557
557
  return referenceToExposed(context, name, empty());
558
558
  }
559
559
  else {
560
- return new FSharpType(/* Union */ 1, [new FSharpUnion(empty(), name, map((Item_3) => (new FSharpUnionCase(/* Typed */ 1, [Item_3])), caseTypes), false, empty(), empty())]);
560
+ return new FSharpType(/* Union */ 1, [new FSharpUnion(empty(), name, map((Item_3) => (new FSharpUnionCase(/* Typed */ 1, [Item_3])), caseTypes), false, empty(), empty(), empty())]);
561
561
  }
562
562
  }
563
563
 
@@ -714,8 +714,226 @@ function $007CRememberedTypeLiteral$007C_$007C(context, glueType) {
714
714
  }
715
715
  }
716
716
 
717
+ function caseNameOf(typ) {
718
+ let name_6;
719
+ const lastSegment = (name) => trim(last(split(name, ["."], undefined, 0)), "`");
720
+ let option_7;
721
+ let matchResult, elementType, typeReference, mappedInfo, name_2, elementType_1, innerType;
722
+ switch (typ.tag) {
723
+ case 8: {
724
+ switch (typ.fields[0].tag) {
725
+ case 1: {
726
+ matchResult = 1;
727
+ break;
728
+ }
729
+ case 2: {
730
+ matchResult = 2;
731
+ break;
732
+ }
733
+ case 5: {
734
+ matchResult = 3;
735
+ break;
736
+ }
737
+ case 3: {
738
+ matchResult = 4;
739
+ break;
740
+ }
741
+ case 4: {
742
+ matchResult = 5;
743
+ break;
744
+ }
745
+ case 7: {
746
+ matchResult = 6;
747
+ break;
748
+ }
749
+ case 6: {
750
+ matchResult = 7;
751
+ break;
752
+ }
753
+ default:
754
+ matchResult = 0;
755
+ }
756
+ break;
757
+ }
758
+ case 18: {
759
+ matchResult = 8;
760
+ break;
761
+ }
762
+ case 11: {
763
+ switch (typ.fields[0].Name) {
764
+ case "ResizeArray": {
765
+ if (!isEmpty(typ.fields[0].TypeArguments)) {
766
+ if (isEmpty(tail_1(typ.fields[0].TypeArguments))) {
767
+ matchResult = 9;
768
+ elementType = head_1(typ.fields[0].TypeArguments);
769
+ }
770
+ else {
771
+ matchResult = 10;
772
+ typeReference = typ.fields[0];
773
+ }
774
+ }
775
+ else {
776
+ matchResult = 10;
777
+ typeReference = typ.fields[0];
778
+ }
779
+ break;
780
+ }
781
+ case "ReadonlyArray": {
782
+ if (!isEmpty(typ.fields[0].TypeArguments)) {
783
+ if (isEmpty(tail_1(typ.fields[0].TypeArguments))) {
784
+ matchResult = 9;
785
+ elementType = head_1(typ.fields[0].TypeArguments);
786
+ }
787
+ else {
788
+ matchResult = 10;
789
+ typeReference = typ.fields[0];
790
+ }
791
+ }
792
+ else {
793
+ matchResult = 10;
794
+ typeReference = typ.fields[0];
795
+ }
796
+ break;
797
+ }
798
+ default: {
799
+ matchResult = 10;
800
+ typeReference = typ.fields[0];
801
+ }
802
+ }
803
+ break;
804
+ }
805
+ case 7: {
806
+ matchResult = 11;
807
+ mappedInfo = typ.fields[0];
808
+ break;
809
+ }
810
+ case 13: {
811
+ matchResult = 12;
812
+ name_2 = typ.fields[0];
813
+ break;
814
+ }
815
+ case 14: {
816
+ matchResult = 13;
817
+ elementType_1 = typ.fields[0];
818
+ break;
819
+ }
820
+ case 19: {
821
+ matchResult = 13;
822
+ elementType_1 = typ.fields[0].fields[0];
823
+ break;
824
+ }
825
+ case 3: {
826
+ matchResult = 14;
827
+ innerType = typ.fields[0];
828
+ break;
829
+ }
830
+ case 16: {
831
+ matchResult = 15;
832
+ break;
833
+ }
834
+ case 12: {
835
+ matchResult = 16;
836
+ break;
837
+ }
838
+ default:
839
+ matchResult = 17;
840
+ }
841
+ switch (matchResult) {
842
+ case 0: {
843
+ option_7 = "String";
844
+ break;
845
+ }
846
+ case 1: {
847
+ option_7 = "Int";
848
+ break;
849
+ }
850
+ case 2: {
851
+ option_7 = "Float";
852
+ break;
853
+ }
854
+ case 3: {
855
+ option_7 = "Number";
856
+ break;
857
+ }
858
+ case 4: {
859
+ option_7 = "Bool";
860
+ break;
861
+ }
862
+ case 5: {
863
+ option_7 = "Unit";
864
+ break;
865
+ }
866
+ case 6: {
867
+ option_7 = "BigInt";
868
+ break;
869
+ }
870
+ case 7: {
871
+ option_7 = undefined;
872
+ break;
873
+ }
874
+ case 8: {
875
+ option_7 = "Obj";
876
+ break;
877
+ }
878
+ case 9: {
879
+ const option_1 = caseNameOf(elementType);
880
+ option_7 = ((option_1 != null) ? (option_1 + "Array") : undefined);
881
+ break;
882
+ }
883
+ case 10: {
884
+ option_7 = lastSegment(typeReference.Name);
885
+ break;
886
+ }
887
+ case 11: {
888
+ option_7 = lastSegment(mappedInfo.Name);
889
+ break;
890
+ }
891
+ case 12: {
892
+ option_7 = trimStart(name_2, "\'");
893
+ break;
894
+ }
895
+ case 13: {
896
+ const option_3 = caseNameOf(elementType_1);
897
+ option_7 = ((option_3 != null) ? (option_3 + "Array") : undefined);
898
+ break;
899
+ }
900
+ case 14: {
901
+ const option_5 = caseNameOf(innerType);
902
+ option_7 = ((option_5 != null) ? (option_5 + "Option") : undefined);
903
+ break;
904
+ }
905
+ case 15: {
906
+ option_7 = "Function";
907
+ break;
908
+ }
909
+ case 16: {
910
+ option_7 = "Tuple";
911
+ break;
912
+ }
913
+ default:
914
+ option_7 = undefined;
915
+ }
916
+ if (option_7 != null) {
917
+ return (name_6 = sanitizeTypeName(option_7), name_6[0].toUpperCase() + substring(name_6, 1));
918
+ }
919
+ else {
920
+ return undefined;
921
+ }
922
+ }
923
+
717
924
  function erasedUnion(name, typeParameters, caseTypes) {
718
- return new FSharpUnion(ofArray([FSharpAttribute.RequireQualifiedAccess, FSharpAttribute.Erase]), name, mapIndexed((index, caseType) => (new FSharpUnionCase(/* Field */ 2, [`Case${index + 1}`, caseType])), caseTypes), false, typeParameters, empty());
925
+ const names = map(caseNameOf, caseTypes);
926
+ return new FSharpUnion(ofArray([FSharpAttribute.RequireQualifiedAccess, FSharpAttribute.Erase]), name, map2((caseName, caseType) => (new FSharpUnionCase(/* Field */ 2, [caseName, caseType])), ((forAll((option) => (option != null), names) && (length(List_distinct(names, {
927
+ Equals: equals,
928
+ GetHashCode: (x) => (structuralHash(x) | 0),
929
+ })) === length(names))) && forAll((name_1) => {
930
+ if (!equals(name_1, "Tag")) {
931
+ return !equals(name_1, "Tags");
932
+ }
933
+ else {
934
+ return false;
935
+ }
936
+ }, names)) ? map(value_7, names) : mapIndexed((index, _arg) => (`Case${index + 1}`), caseTypes), caseTypes), false, typeParameters, empty(), empty());
719
937
  }
720
938
 
721
939
  function referenceToExposed(context, name, typeParameterNames) {
@@ -806,7 +1024,7 @@ function transformUnionType(context, cases) {
806
1024
  }
807
1025
  default: {
808
1026
  const cases_1 = map((Item_1) => (new FSharpUnionCase(/* Typed */ 1, [Item_1])), caseTypes);
809
- return new FSharpType(/* Union */ 1, [new FSharpUnion(empty(), `U${length(caseTypes)}`, cases_1, isOptional, empty(), empty())]);
1027
+ return new FSharpType(/* Union */ 1, [new FSharpUnion(empty(), `U${length(caseTypes)}`, cases_1, isOptional, empty(), empty(), empty())]);
810
1028
  }
811
1029
  }
812
1030
  }
@@ -818,7 +1036,7 @@ function transformUnionType(context, cases) {
818
1036
  });
819
1037
  let option_3;
820
1038
  const option_1 = tryOptimizeUnionType(context, name, others_1);
821
- option_3 = ((option_1 != null) ? ((typ = option_1, (typ.tag === 1) ? ((unionInfo = typ.fields[0], new FSharpType(/* Union */ 1, [new FSharpUnion(unionInfo.Attributes, unionInfo.Name, unionInfo.Cases, unionInfo.IsOptional, declaredTypeParameters_1(typeParameterNames), unionInfo.Constants)]))) : typ)) : undefined);
1039
+ option_3 = ((option_1 != null) ? ((typ = option_1, (typ.tag === 1) ? ((unionInfo = typ.fields[0], new FSharpType(/* Union */ 1, [new FSharpUnion(unionInfo.Attributes, unionInfo.Name, unionInfo.Cases, unionInfo.IsOptional, declaredTypeParameters_1(typeParameterNames), unionInfo.Constants, unionInfo.Conversions)]))) : typ)) : undefined);
822
1040
  if (option_3 != null) {
823
1041
  TransformContext__ExposeType_Z1D58A540(context, option_3);
824
1042
  }
@@ -2539,7 +2757,7 @@ function paramObjectParameterSets(context, members) {
2539
2757
  const context_1 = sanitizeNameAndPushScope(parameter.Name, context)[1];
2540
2758
  void (TransformContext__get_State(context_1).UnionAliasesBeingExpanded.push(fullName_2));
2541
2759
  try {
2542
- return new FSharpParameter(parameter.Attributes, parameter.Name, parameter.IsOptional ? true : nullable_1, new FSharpType(/* Union */ 1, [new FSharpUnion(empty(), "", map((arg_1) => (new FSharpUnionCase(/* Typed */ 1, [transformType(context_1, arrayAsInput(arg_1))])), cases_1), false, empty(), empty())]), parameter.OriginalGlueMember);
2760
+ return new FSharpParameter(parameter.Attributes, parameter.Name, parameter.IsOptional ? true : nullable_1, new FSharpType(/* Union */ 1, [new FSharpUnion(empty(), "", map((arg_1) => (new FSharpUnionCase(/* Typed */ 1, [transformType(context_1, arrayAsInput(arg_1))])), cases_1), false, empty(), empty(), empty())]), parameter.OriginalGlueMember);
2543
2761
  }
2544
2762
  finally {
2545
2763
  TransformContext__get_State(context_1).UnionAliasesBeingExpanded.splice(TransformContext__get_State(context_1).UnionAliasesBeingExpanded.length - 1, 1);
@@ -3079,7 +3297,7 @@ export function TypeAliasDeclaration_tryTransformKeyOf(aliasName, glueType) {
3079
3297
  return undefined;
3080
3298
  }
3081
3299
  else {
3082
- return new FSharpType(/* Union */ 1, [new FSharpUnion(ofArray([FSharpAttribute.RequireQualifiedAccess, new FSharpAttribute(/* StringEnum */ 12, [0])]), sanitizeTypeName(aliasName), cases, false, empty(), empty())]);
3300
+ return new FSharpType(/* Union */ 1, [new FSharpUnion(ofArray([FSharpAttribute.RequireQualifiedAccess, new FSharpAttribute(/* StringEnum */ 12, [0])]), sanitizeTypeName(aliasName), cases, false, empty(), empty(), empty())]);
3083
3301
  }
3084
3302
  }
3085
3303
 
@@ -3109,7 +3327,7 @@ export function TypeAliasDeclaration_transformLiteral(xmlDoc, typeAliasName, lit
3109
3327
  default: {
3110
3328
  const value = literalInfo.fields[0];
3111
3329
  const sanitizeResult = sanitizeTypeNameWithResult(value);
3112
- return new FSharpType(/* Union */ 1, [new FSharpUnion(ofArray([FSharpAttribute.RequireQualifiedAccess, new FSharpAttribute(/* StringEnum */ 12, [0])]), typeAliasName, singleton(new FSharpUnionCase(/* Named */ 0, [new FSharpUnionCaseNamed(toList(delay(() => (sanitizeResult.IsDifferent ? singleton_1(new FSharpAttribute(/* CompiledName */ 13, [removeSurroundingQuotes(value)])) : empty_1()))), sanitizeResult.Name)])), false, empty(), empty())]);
3330
+ return new FSharpType(/* Union */ 1, [new FSharpUnion(ofArray([FSharpAttribute.RequireQualifiedAccess, new FSharpAttribute(/* StringEnum */ 12, [0])]), typeAliasName, singleton(new FSharpUnionCase(/* Named */ 0, [new FSharpUnionCaseNamed(toList(delay(() => (sanitizeResult.IsDifferent ? singleton_1(new FSharpAttribute(/* CompiledName */ 13, [removeSurroundingQuotes(value)])) : empty_1()))), sanitizeResult.Name)])), false, empty(), empty(), empty())]);
3113
3331
  }
3114
3332
  }
3115
3333
  }
@@ -3757,7 +3975,7 @@ function tryOptimizeUnionType(context, typeName, cases) {
3757
3975
  GetHashCode: (x_6) => (safeHash(x_6) | 0),
3758
3976
  })));
3759
3977
  const fieldCases_1 = transformFieldCases(literalCases_1);
3760
- return new FSharpType(/* Union */ 1, [new FSharpUnion(toList(delay(() => append_1(singleton_1(FSharpAttribute.RequireQualifiedAccess), delay(() => (isEmpty(fieldCases_1) ? singleton_1(new FSharpAttribute(/* StringEnum */ 12, [0])) : singleton_1(new FSharpAttribute(/* EraseWithCaseRules */ 7, [0]))))))), typeName, append(literalCases_1, fieldCases_1), false, empty(), empty())]);
3978
+ return new FSharpType(/* Union */ 1, [new FSharpUnion(toList(delay(() => append_1(singleton_1(FSharpAttribute.RequireQualifiedAccess), delay(() => (isEmpty(fieldCases_1) ? singleton_1(new FSharpAttribute(/* StringEnum */ 12, [0])) : singleton_1(new FSharpAttribute(/* EraseWithCaseRules */ 7, [0]))))))), typeName, append(literalCases_1, fieldCases_1), false, empty(), empty(), empty())]);
3761
3979
  }
3762
3980
  else if (isNumericOnly && !isEmpty(otherCases)) {
3763
3981
  const literalCases_2 = List_distinct(map((value_3) => {
@@ -3784,7 +4002,7 @@ function tryOptimizeUnionType(context, typeName, cases) {
3784
4002
  Equals: equals,
3785
4003
  GetHashCode: (x_7) => (safeHash(x_7) | 0),
3786
4004
  });
3787
- return new FSharpType(/* Union */ 1, [new FSharpUnion(ofArray([FSharpAttribute.RequireQualifiedAccess, new FSharpAttribute(/* EraseWithCaseRules */ 7, [0])]), typeName, append(literalCases_2, transformFieldCases(literalCases_2)), false, empty(), empty())]);
4005
+ return new FSharpType(/* Union */ 1, [new FSharpUnion(ofArray([FSharpAttribute.RequireQualifiedAccess, new FSharpAttribute(/* EraseWithCaseRules */ 7, [0])]), typeName, append(literalCases_2, transformFieldCases(literalCases_2)), false, empty(), empty(), empty())]);
3788
4006
  }
3789
4007
  else if (isNumericOnly) {
3790
4008
  return new FSharpType(/* Enum */ 0, [new FSharpEnum(typeName, List_distinct(map((value_5) => {
@@ -3828,7 +4046,7 @@ function tryOptimizeUnionType(context, typeName, cases) {
3828
4046
  return [patternInput_2[0], (matchValue_4 = transformType(patternInput_2[1], property_4.Type), (matchValue_4.tag === 3) ? matchValue_4 : (property_4.IsOptional ? (new FSharpType(/* Option */ 3, [matchValue_4])) : matchValue_4))];
3829
4047
  }, filter((property_3) => (property_3.Name !== tagName_1), tupledArg_1[1][1]))]);
3830
4048
  }, zip(deduplicateCaseNames(map((arg) => literalCaseInfo(arg[0]), taggedCases)), taggedCases));
3831
- return new FSharpType(/* Union */ 1, [new FSharpUnion(ofArray([FSharpAttribute.RequireQualifiedAccess, new FSharpAttribute(/* TypeScriptTaggedUnion */ 8, [removeSurroundingQuotes(tagName_1), 0])]), typeName, cases_6, false, empty(), empty())]);
4049
+ return new FSharpType(/* Union */ 1, [new FSharpUnion(ofArray([FSharpAttribute.RequireQualifiedAccess, new FSharpAttribute(/* TypeScriptTaggedUnion */ 8, [removeSurroundingQuotes(tagName_1), 0])]), typeName, cases_6, false, empty(), empty(), empty())]);
3832
4050
  }
3833
4051
  }
3834
4052
 
@@ -4065,47 +4283,53 @@ function aliasOfUnion(scope, cases, unionType) {
4065
4283
  const matchValue = tryOptimizeUnionType(context, scope.Name, cases_1);
4066
4284
  if (matchValue == null) {
4067
4285
  const matchValue_1 = partition(isNullable, cases_1);
4068
- let matchResult_1, single, others_4;
4069
- if (!isEmpty(matchValue_1[0])) {
4070
- if (!isEmpty(matchValue_1[1])) {
4071
- if (isEmpty(tail_1(matchValue_1[1]))) {
4072
- matchResult_1 = 0;
4073
- single = head_1(matchValue_1[1]);
4074
- }
4075
- else if (length(matchValue_1[1]) > 9) {
4076
- matchResult_1 = 1;
4077
- others_4 = matchValue_1[1];
4078
- }
4079
- else {
4080
- matchResult_1 = 2;
4081
- }
4286
+ let matchResult_1, single, others_5, others_6;
4287
+ if (isEmpty(matchValue_1[0])) {
4288
+ if (length(matchValue_1[1]) > 1) {
4289
+ matchResult_1 = 1;
4290
+ others_5 = matchValue_1[1];
4082
4291
  }
4083
4292
  else if (length(matchValue_1[1]) > 9) {
4084
- matchResult_1 = 1;
4085
- others_4 = matchValue_1[1];
4293
+ matchResult_1 = 2;
4294
+ others_6 = matchValue_1[1];
4086
4295
  }
4087
4296
  else {
4297
+ matchResult_1 = 3;
4298
+ }
4299
+ }
4300
+ else if (!isEmpty(matchValue_1[1])) {
4301
+ if (isEmpty(tail_1(matchValue_1[1]))) {
4302
+ matchResult_1 = 0;
4303
+ single = head_1(matchValue_1[1]);
4304
+ }
4305
+ else if (length(matchValue_1[1]) > 9) {
4088
4306
  matchResult_1 = 2;
4307
+ others_6 = matchValue_1[1];
4308
+ }
4309
+ else {
4310
+ matchResult_1 = 3;
4089
4311
  }
4090
4312
  }
4091
4313
  else if (length(matchValue_1[1]) > 9) {
4092
- matchResult_1 = 1;
4093
- others_4 = matchValue_1[1];
4314
+ matchResult_1 = 2;
4315
+ others_6 = matchValue_1[1];
4094
4316
  }
4095
4317
  else {
4096
- matchResult_1 = 2;
4318
+ matchResult_1 = 3;
4097
4319
  }
4098
4320
  switch (matchResult_1) {
4099
4321
  case 0:
4100
4322
  return aliasOf(scope, new FSharpType(/* Option */ 3, [transformType(TransformContext__PushScope_27AED5E3(context, "Value"), single)]));
4101
4323
  case 1:
4102
- return erasedUnionOf(others_4);
4324
+ return erasedUnionOf(others_5);
4325
+ case 2:
4326
+ return erasedUnionOf(others_6);
4103
4327
  default:
4104
4328
  return aliasOf(scope, transformType(context, unionType));
4105
4329
  }
4106
4330
  }
4107
4331
  else {
4108
- return (matchValue.tag === 1) ? ((unionInfo = matchValue.fields[0], new FSharpType(/* Union */ 1, [new FSharpUnion(unionInfo.Attributes, unionInfo.Name, unionInfo.Cases, unionInfo.IsOptional, scope.TypeParameters.Value.TypeParameters, unionInfo.Constants)]))) : ((typ = matchValue, typ));
4332
+ return (matchValue.tag === 1) ? ((unionInfo = matchValue.fields[0], new FSharpType(/* Union */ 1, [new FSharpUnion(unionInfo.Attributes, unionInfo.Name, unionInfo.Cases, unionInfo.IsOptional, scope.TypeParameters.Value.TypeParameters, unionInfo.Constants, unionInfo.Conversions)]))) : ((typ = matchValue, typ));
4109
4333
  }
4110
4334
  }
4111
4335
  }
@@ -128,7 +128,7 @@ export function withoutName(typ) {
128
128
  }
129
129
  case 1: {
130
130
  const info_3 = typ.fields[0];
131
- return new FSharpType(/* Union */ 1, [new FSharpUnion(info_3.Attributes, "", info_3.Cases, info_3.IsOptional, info_3.TypeParameters, info_3.Constants)]);
131
+ return new FSharpType(/* Union */ 1, [new FSharpUnion(info_3.Attributes, "", info_3.Cases, info_3.IsOptional, info_3.TypeParameters, info_3.Constants, info_3.Conversions)]);
132
132
  }
133
133
  case 0:
134
134
  return new FSharpType(/* Enum */ 0, [new FSharpEnum("", typ.fields[0].Cases)]);
@@ -47,7 +47,7 @@ export function transformEnum(glueEnum) {
47
47
  }, stringValues), {
48
48
  Equals: equals,
49
49
  GetHashCode: (x_1) => (safeHash(x_1) | 0),
50
- }), false, empty(), empty())]);
50
+ }), false, empty(), empty(), empty())]);
51
51
  }
52
52
  }
53
53
  else if (isEmpty(stringValues)) {
@@ -74,7 +74,7 @@ export function transformEnum(glueEnum) {
74
74
  return constant("String", (arg = removeSurroundingQuotes(matchValue_4.fields[0]), toText(printf("%A"))(arg)));
75
75
  }
76
76
  }, glueEnum.Members);
77
- return new FSharpType(/* Union */ 1, [new FSharpUnion(ofArray([FSharpAttribute.RequireQualifiedAccess, FSharpAttribute.Erase]), name, toList(delay(() => append(exists((constant_1) => (constant_1.Case === "String"), constants) ? singleton(new FSharpUnionCase(/* Field */ 2, ["String", new FSharpType(/* Primitive */ 8, [FSharpPrimitive.String$])])) : empty_1(), delay(() => (exists((constant_2) => (constant_2.Case === "Number"), constants) ? singleton(new FSharpUnionCase(/* Field */ 2, ["Number", new FSharpType(/* Primitive */ 8, [FSharpPrimitive.Float])])) : empty_1()))))), false, empty(), constants)]);
77
+ return new FSharpType(/* Union */ 1, [new FSharpUnion(ofArray([FSharpAttribute.RequireQualifiedAccess, FSharpAttribute.Erase]), name, toList(delay(() => append(exists((constant_1) => (constant_1.Case === "String"), constants) ? singleton(new FSharpUnionCase(/* Field */ 2, ["String", new FSharpType(/* Primitive */ 8, [FSharpPrimitive.String$])])) : empty_1(), delay(() => (exists((constant_2) => (constant_2.Case === "Number"), constants) ? singleton(new FSharpUnionCase(/* Field */ 2, ["Number", new FSharpType(/* Primitive */ 8, [FSharpPrimitive.Float])])) : empty_1()))))), false, empty(), constants, empty())]);
78
78
  }
79
79
  }
80
80
 
@@ -161,7 +161,7 @@ export function mapFSharpType(seadledTypes, typ) {
161
161
  default:
162
162
  return case$;
163
163
  }
164
- }, unionInfo.Cases), unionInfo.IsOptional, unionInfo.TypeParameters, unionInfo.Constants)]);
164
+ }, unionInfo.Cases), unionInfo.IsOptional, unionInfo.TypeParameters, unionInfo.Constants, unionInfo.Conversions)]);
165
165
  case 6:
166
166
  return new FSharpType(/* Tuple */ 12, [map((typ_6) => mapFSharpType(seadledTypes, typ_6), types)]);
167
167
  case 7:
@@ -41,7 +41,7 @@ export function tryUnwrapOption(typ) {
41
41
  case 0:
42
42
  return underlyingType;
43
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)]);
44
+ return new FSharpType(/* Union */ 1, [new FSharpUnion(unionInfo_1.Attributes, unionInfo_1.Name, unionInfo_1.Cases, false, unionInfo_1.TypeParameters, unionInfo_1.Constants, unionInfo_1.Conversions)]);
45
45
  default:
46
46
  return undefined;
47
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glutinum/cli",
3
- "version": "1.0.0-beta.11",
3
+ "version": "1.0.0-beta.13",
4
4
  "description": "TypeScript definition to F# bindings converter",
5
5
  "type": "module",
6
6
  "main": "index.js",