@glutinum/cli 1.0.0-beta.5 → 1.0.0-beta.6

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.
@@ -849,22 +849,43 @@ function printEnum(printer, enumInfo) {
849
849
  }
850
850
 
851
851
  function printTypeAlias(printer, aliasInfo) {
852
- const aliasedType = printType(aliasInfo.Type);
852
+ let aliasedType;
853
+ const text = printType(aliasInfo.Type);
854
+ let matchResult;
855
+ if (aliasInfo.Type.tag === 16) {
856
+ if (text.startsWith("(") && text.endsWith(")")) {
857
+ matchResult = 0;
858
+ }
859
+ else {
860
+ matchResult = 1;
861
+ }
862
+ }
863
+ else {
864
+ matchResult = 1;
865
+ }
866
+ switch (matchResult) {
867
+ case 0: {
868
+ aliasedType = substring(text, 1, text.length - 2);
869
+ break;
870
+ }
871
+ default:
872
+ aliasedType = text;
873
+ }
853
874
  const usageText = join(" ", append(singleton(aliasedType), choose((_arg) => {
854
- let matchResult, constraint_;
875
+ let matchResult_1, constraint_;
855
876
  if (_arg.tag === 1) {
856
877
  if (_arg.fields[0].Constraint != null) {
857
- matchResult = 0;
878
+ matchResult_1 = 0;
858
879
  constraint_ = _arg.fields[0].Constraint;
859
880
  }
860
881
  else {
861
- matchResult = 1;
882
+ matchResult_1 = 1;
862
883
  }
863
884
  }
864
885
  else {
865
- matchResult = 1;
886
+ matchResult_1 = 1;
866
887
  }
867
- switch (matchResult) {
888
+ switch (matchResult_1) {
868
889
  case 0:
869
890
  return printType(constraint_);
870
891
  default:
@@ -8,8 +8,8 @@ import { transformComment, TransformCommentResult_$reflection } from "./Transfor
8
8
  import { add, contains as contains_2, union, empty as empty_2, ofSeq, singleton as singleton_2, ofList, FSharpSet__Contains } from "../fable_modules/fable-library-js.5.17.2/Set.js";
9
9
  import { aggregatedExports, replaceSelfReference, isUnitAlias, typedArrayNames, transformPrimitive, requiredBeforeParamArray, isDataObject, Interface_makePartial, tryUnwrapOption, iteratorNames } from "./Transformer/Utils.js";
10
10
  import { value as value_7, unwrap, toArray, defaultArg } from "../fable_modules/fable-library-js.5.17.2/Option.js";
11
- import { zip, mapFold, item, concat as concat_1, reverse, iterate, cons, foldBack, fold, tryFind, ofSeq as ofSeq_1, forAll as forAll_1, sortBy, tryPick, truncate, exists, contains, partition, mapIndexed, filter, append, length, collect, tryLast, choose, tryHead, singleton, empty, ofArray, map, head as head_1, tail as tail_3, isEmpty } from "../fable_modules/fable-library-js.5.17.2/List.js";
12
- import { aliasArities, namedTypeParameters, membersNameUndeclaredTypeParameters, mentionsTypeParameter, ownTypeParameterDefaults, typeParameterNames as typeParameterNames_2, unconstrained, memberTypeParameterNames, typeArguments, declaredTypeParameters } from "./Transformer/TypeParameters.js";
11
+ import { zip, mapFold, item, concat as concat_1, reverse, iterate, cons, foldBack, fold, tryFind, ofSeq as ofSeq_1, forAll as forAll_1, sortBy, tryPick, truncate, contains, exists, partition, mapIndexed, filter, append, length, collect, tryLast, choose, tryHead, singleton, empty, ofArray, map, head as head_1, tail as tail_3, isEmpty } from "../fable_modules/fable-library-js.5.17.2/List.js";
12
+ import { aliasArities, namedTypeParameters, membersNameUndeclaredTypeParameters, mentionsTypeParameter, ownTypeParameterDefaults, typeParameterNames as typeParameterNames_2, unconstrained, memberTypeParameterNames, typeArguments, declaredTypeParameters as declaredTypeParameters_1 } from "./Transformer/TypeParameters.js";
13
13
  import { List_groupBy, List_distinct } from "../fable_modules/fable-library-js.5.17.2/Seq2.js";
14
14
  import { uncurry2, curry2, Lazy, structuralHash, Exception, numberHash, int32ToString, disposeSafe, getEnumerator, defaultOf, comparePrimitives, safeHash, equals, stringHash } from "../fable_modules/fable-library-js.5.17.2/Util.js";
15
15
  import { replace, trim, printf, toFail, substring, interpolate, concat } from "../fable_modules/fable-library-js.5.17.2/String.js";
@@ -506,7 +506,7 @@ function transformTupleType(context, glueTypes) {
506
506
  }
507
507
 
508
508
  function anonymousInterface(context, name, typeParameterNames, members, inheritance) {
509
- return new FSharpInterface(ofArray([FSharpAttribute.AllowNullLiteral, FSharpAttribute.Interface]), name, empty(), TransformContext__get_OriginalScopeName(context), declaredTypeParameters(typeParameterNames), members, inheritance);
509
+ return new FSharpInterface(ofArray([FSharpAttribute.AllowNullLiteral, FSharpAttribute.Interface]), name, empty(), TransformContext__get_OriginalScopeName(context), declaredTypeParameters_1(typeParameterNames), members, inheritance);
510
510
  }
511
511
 
512
512
  function mappedReference(context, name, typeParameterNames) {
@@ -724,7 +724,7 @@ function UtilityType_transform(context, utilityType) {
724
724
  Equals: (x_2, y_2) => (x_2 === y_2),
725
725
  GetHashCode: (x_2) => (stringHash(x_2) | 0),
726
726
  });
727
- const freeTypeParameters = declaredTypeParameters(freeTypeParameterNames_2);
727
+ const freeTypeParameters = declaredTypeParameters_1(freeTypeParameterNames_2);
728
728
  const creates = (!isEmpty(members) && isDataObject(members)) ? paramObjectCreateMembers(context, new FSharpType(/* Mapped */ 7, [new FSharpMapped(name_4, typeArguments(freeTypeParameterNames_2))]), members) : empty();
729
729
  TransformContext__ExposeType_Z1D58A540(context, new FSharpType(/* Interface */ 5, [anonymousInterface(context, name_4, freeTypeParameterNames_2, append(TransformMembers_toFSharpMember(context, members), creates), empty())]));
730
730
  return new FSharpType(/* Mapped */ 7, [new FSharpMapped(TransformContext__ReferenceName_Z721C83C5(context, name_4), freeTypeParameters)]);
@@ -847,7 +847,7 @@ function transformUnionType(context, cases) {
847
847
  Equals: (x_2, y_2) => (x_2 === y_2),
848
848
  GetHashCode: (x_2) => (stringHash(x_2) | 0),
849
849
  });
850
- TransformContext__ExposeType_Z1D58A540(context, new FSharpType(/* Union */ 1, [erasedUnion(name_1, declaredTypeParameters(typeParameterNames_1), caseTypes)]));
850
+ TransformContext__ExposeType_Z1D58A540(context, new FSharpType(/* Union */ 1, [erasedUnion(name_1, declaredTypeParameters_1(typeParameterNames_1), caseTypes)]));
851
851
  const reference = referenceToExposed(context, name_1, typeParameterNames_1);
852
852
  if (isOptional) {
853
853
  return new FSharpType(/* Option */ 3, [reference]);
@@ -870,7 +870,7 @@ function transformUnionType(context, cases) {
870
870
  });
871
871
  let option_3;
872
872
  const option_1 = tryOptimizeUnionType(context, name, others);
873
- 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(typeParameterNames), unionInfo.Constants)]))) : typ)) : undefined);
873
+ 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);
874
874
  if (option_3 != null) {
875
875
  TransformContext__ExposeType_Z1D58A540(context, option_3);
876
876
  }
@@ -879,6 +879,35 @@ function transformUnionType(context, cases) {
879
879
  }
880
880
  }
881
881
 
882
+ function isLambdaSignature(parameters, ownTypeParameters, declaredTypeParameters) {
883
+ const hasConstraint = exists((_arg) => {
884
+ let matchResult;
885
+ if (_arg.tag === 1) {
886
+ if (_arg.fields[0].Constraint != null) {
887
+ matchResult = 0;
888
+ }
889
+ else {
890
+ matchResult = 1;
891
+ }
892
+ }
893
+ else {
894
+ matchResult = 1;
895
+ }
896
+ switch (matchResult) {
897
+ case 0:
898
+ return true;
899
+ default:
900
+ return false;
901
+ }
902
+ }, declaredTypeParameters);
903
+ if (((length(parameters) <= 1) && !exists((_arg_1) => _arg_1.IsSpread, parameters)) && isEmpty(ownTypeParameters)) {
904
+ return !hasConstraint;
905
+ }
906
+ else {
907
+ return false;
908
+ }
909
+ }
910
+
882
911
  function transformFunctionType(context, functionTypeInfo) {
883
912
  const paremeters = filter((parameter) => (parameter.Name !== "this"), functionTypeInfo.Parameters);
884
913
  let matchResult;
@@ -1389,7 +1418,7 @@ function transformType(context_mut, glueType_mut) {
1389
1418
  case 4:
1390
1419
  return new FSharpType(/* Option */ 3, [transformType(context, glueType_21)]);
1391
1420
  case 5:
1392
- return new FSharpType(/* ThisType */ 15, [new FSharpThisType(sanitizeTypeName(thisTypeInfo.Name), declaredTypeParameters(map((_arg) => _arg.Name, thisTypeInfo.TypeParameters)))]);
1421
+ return new FSharpType(/* ThisType */ 15, [new FSharpThisType(sanitizeTypeName(thisTypeInfo.Name), declaredTypeParameters_1(map((_arg) => _arg.Name, thisTypeInfo.TypeParameters)))]);
1393
1422
  case 6:
1394
1423
  return transformTupleType(context, glueTypes);
1395
1424
  case 7:
@@ -3230,7 +3259,7 @@ function transformParamObjectClass(context, name, documentation, members) {
3230
3259
  else {
3231
3260
  patternInput_1 = [paramObjectConstructor(typeLiteralParameters), empty()];
3232
3261
  }
3233
- return new FSharpClass(toList(delay(() => append_1(xmlDocInfo.ObsoleteAttributes, delay(() => append_1(singleton_1(new FSharpAttribute(/* Global */ 21, [undefined])), delay(() => singleton_1(FSharpAttribute.AllowNullLiteral))))))), xmlDocInfo.XmlDoc, name, declaredTypeParameters(typeParameterNames), patternInput_1[0], patternInput_1[1], explicitFields);
3262
+ return new FSharpClass(toList(delay(() => append_1(xmlDocInfo.ObsoleteAttributes, delay(() => append_1(singleton_1(new FSharpAttribute(/* Global */ 21, [undefined])), delay(() => singleton_1(FSharpAttribute.AllowNullLiteral))))))), xmlDocInfo.XmlDoc, name, declaredTypeParameters_1(typeParameterNames), patternInput_1[0], patternInput_1[1], explicitFields);
3234
3263
  }
3235
3264
 
3236
3265
  function transformCallbackReturnType(context, returnType) {
@@ -3329,7 +3358,12 @@ function tryTransformCallableInterface(context, info) {
3329
3358
  iterate((typ) => {
3330
3359
  TransformContext__ExposeType_Z1D58A540(context_1, typ);
3331
3360
  }, exposeSpecializedAlias(name, empty(), empty(), reverse(typeParameters.TypeParameters)));
3332
- return new FSharpType(/* Delegate */ 20, [new FSharpDelegate(xmlDocInfo.XmlDoc, name, typeParameters.TypeParameters, requiredBeforeParamArray(map((parameter) => transformParameter(context_1, parameter), callSignature_1.Parameters)), transformCallbackReturnType(TransformContext__PushScope_27AED5E3(context_1, "ReturnType"), callSignature_1.Type))]);
3361
+ if (isLambdaSignature(callSignature_1.Parameters, transformTypeParameters(context_1, callSignature_1.TypeParameters).TypeParameters, typeParameters.TypeParameters)) {
3362
+ return new FSharpType(/* TypeAlias */ 9, [new FSharpTypeAlias(toList(delay(() => xmlDocInfo.ObsoleteAttributes)), name, xmlDocInfo.XmlDoc, new FSharpType(/* Function */ 16, [new FSharpFunctionType(map((parameter) => transformParameter(context_1, parameter), callSignature_1.Parameters), transformCallbackReturnType(TransformContext__PushScope_27AED5E3(context_1, "ReturnType"), callSignature_1.Type))]), typeParameters.TypeParameters)]);
3363
+ }
3364
+ else {
3365
+ return new FSharpType(/* Delegate */ 20, [new FSharpDelegate(xmlDocInfo.XmlDoc, name, typeParameters.TypeParameters, requiredBeforeParamArray(map((parameter_1) => transformParameter(context_1, parameter_1), callSignature_1.Parameters)), transformCallbackReturnType(TransformContext__PushScope_27AED5E3(context_1, "ReturnType"), callSignature_1.Type))]);
3366
+ }
3333
3367
  }
3334
3368
  case 1: {
3335
3369
  const patternInput_1 = sanitizeTypeNameAndPushScope(info.Name, context);
@@ -5008,7 +5042,13 @@ function aliasOfFunctionType(scope, functionType) {
5008
5042
  Compare: (x, y) => (comparePrimitives(x, y) | 0),
5009
5043
  });
5010
5044
  const ownTypeParameters = transformTypeParameters(context, filter((typeParameter) => !FSharpSet__Contains(declaredNames, typeParameter.Name), functionType.TypeParameters));
5011
- return new FSharpType(/* Delegate */ 20, [new FSharpDelegate(scope.XmlDoc.XmlDoc, scope.Name, append(scope.TypeParameters.Value.TypeParameters, ownTypeParameters.TypeParameters), requiredBeforeParamArray(map((arg) => TypeParameter_mapFsharpParameter(ownTypeParameters.SealedTypes, transformParameter(context, arg)), functionType.Parameters)), TypeParameter_mapFSharpType(ownTypeParameters.SealedTypes, transformCallbackReturnType(TransformContext__PushScope_27AED5E3(context, "ReturnType"), functionType.Type)))]);
5045
+ const declaredTypeParameters = scope.TypeParameters.Value.TypeParameters;
5046
+ if (isLambdaSignature(functionType.Parameters, ownTypeParameters.TypeParameters, declaredTypeParameters)) {
5047
+ return aliasOf(scope, new FSharpType(/* Function */ 16, [new FSharpFunctionType(map((parameter) => transformParameter(context, parameter), functionType.Parameters), transformCallbackReturnType(TransformContext__PushScope_27AED5E3(context, "ReturnType"), functionType.Type))]));
5048
+ }
5049
+ else {
5050
+ return new FSharpType(/* Delegate */ 20, [new FSharpDelegate(scope.XmlDoc.XmlDoc, scope.Name, append(declaredTypeParameters, ownTypeParameters.TypeParameters), requiredBeforeParamArray(map((arg) => TypeParameter_mapFsharpParameter(ownTypeParameters.SealedTypes, transformParameter(context, arg)), functionType.Parameters)), TypeParameter_mapFSharpType(ownTypeParameters.SealedTypes, transformCallbackReturnType(TransformContext__PushScope_27AED5E3(context, "ReturnType"), functionType.Type)))]);
5051
+ }
5012
5052
  }
5013
5053
 
5014
5054
  function aliasOfTypeLiteral(scope, typeLiteralInfo) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glutinum/cli",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.0-beta.6",
4
4
  "description": "TypeScript definition to F# bindings converter",
5
5
  "type": "module",
6
6
  "main": "index.js",