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

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.
@@ -13,7 +13,7 @@ import { escape, create, isMatch, replace as replace_2 } from "../fable_modules/
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.17.2/Seq.js";
16
- import { List_distinct } from "../fable_modules/fable-library-js.5.17.2/Seq2.js";
16
+ import { List_distinctBy } from "../fable_modules/fable-library-js.5.17.2/Seq2.js";
17
17
 
18
18
  export class Printer {
19
19
  constructor() {
@@ -957,7 +957,7 @@ function printUnion(printer, unionInfo) {
957
957
  }
958
958
  }, unionInfo.Attributes)) {
959
959
  const returnType = printTypeNameWithTypeParameters(unionInfo.Name, unionInfo.TypeParameters);
960
- iterate((caseType) => {
960
+ iterate((caseType_1) => {
961
961
  const enumerator = getEnumerator(["op_Implicit", "op_ErasedCast"]);
962
962
  try {
963
963
  while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
@@ -965,14 +965,21 @@ function printUnion(printer, unionInfo) {
965
965
  Printer__get_NewLine(printer);
966
966
  Printer__Write_Z721C83C5(printer, "[<Emit(\"$0\")>]");
967
967
  Printer__get_NewLine(printer);
968
- Printer__Write_Z721C83C5(printer, `static member ${name_2}(value: ${caseType}) : ${returnType} = nativeOnly`);
968
+ Printer__Write_Z721C83C5(printer, `static member ${name_2}(value: ${caseType_1}) : ${returnType} = nativeOnly`);
969
969
  Printer__get_NewLine(printer);
970
970
  }
971
971
  }
972
972
  finally {
973
973
  disposeSafe(enumerator);
974
974
  }
975
- }, List_distinct(choose((_arg_1) => {
975
+ }, List_distinctBy((caseType) => {
976
+ if (caseType === "JS.Uint8ClampedArray") {
977
+ return "JS.Uint8Array";
978
+ }
979
+ else {
980
+ return caseType;
981
+ }
982
+ }, choose((_arg_1) => {
976
983
  if (_arg_1.tag === 2) {
977
984
  return printType(_arg_1.fields[1]);
978
985
  }
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { GluePrimitive, GlueType, GlueIndexedAccessType } from "../GlueAST.js";
3
- import { typeNodeBuilderFlags, $007CHasTypeFlags$007C_$007C } from "./Utils.js";
3
+ import { typeNodeBuilderFlags, $007CHasTypeFlags$007C_$007C, enclosingDeclarationOf } from "./Utils.js";
4
4
  import { Report_readerError_Z19516DCE } from "./Report.js";
5
5
  import { concat } from "../../fable_modules/fable-library-js.5.17.2/String.js";
6
6
  import { TypeScript_Ts_SyntaxKind__SyntaxKind_get_Name } from "../TypeScript.Extensions.js";
@@ -12,7 +12,7 @@ export function readIndexedAccessType(reader, declaration) {
12
12
  const node = declaration;
13
13
  const tryTypeToTypeNode = (typ, flags) => {
14
14
  try {
15
- return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"]().typeToTypeNode(typ, node, flags);
15
+ return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"]().typeToTypeNode(typ, enclosingDeclarationOf(node), flags);
16
16
  }
17
17
  catch (matchValue) {
18
18
  return undefined;
@@ -2,7 +2,7 @@
2
2
  import { Union } from "../../fable_modules/fable-library-js.5.17.2/Types.js";
3
3
  import { union_type, class_type } from "../../fable_modules/fable-library-js.5.17.2/Reflection.js";
4
4
  import { contains as contains_2, item as item_4 } from "../../fable_modules/fable-library-js.5.17.2/Array.js";
5
- import { tryReadLiteral, resolvedBaseTypeArguments, declaredName, isFromEsLib, isFromEs5Lib, crossesNamespace, modulePathForSymbol, knownExternalTypeNames, isExternalToPackages, importedName, typeLiteralId, readTypeArguments, getFullNameOrEmpty, defaultTypeArguments, isTupleType, withInProgress, Type_NumberLiteral_$007CInt$007CFloat$007COther$007C, Type_StringLiteral_$007CString$007COther$007C, primitiveOfFlags, entityNameText, mainDeclaration, resolveAlias, symbolAtLocation, identifierText, $007CHasTypeFlags$007C_$007C, $007CHasSymbolFlags$007C_$007C, typeNodeBuilderFlags } from "./Utils.js";
5
+ import { tryReadLiteral, resolvedBaseTypeArguments, declaredName, isFromEsLib, isFromEs5Lib, crossesNamespace, modulePathForSymbol, knownExternalTypeNames, isExternalToPackages, importedName, typeLiteralId, readTypeArguments, getFullNameOrEmpty, defaultTypeArguments, isTupleType, withInProgress, Type_NumberLiteral_$007CInt$007CFloat$007COther$007C, Type_StringLiteral_$007CString$007COther$007C, primitiveOfFlags, entityNameText, mainDeclaration, resolveAlias, symbolAtLocation, identifierText, $007CHasTypeFlags$007C_$007C, enclosingDeclarationOf, $007CHasSymbolFlags$007C_$007C, typeNodeBuilderFlags } from "./Utils.js";
6
6
  import { Report_readerError_Z19516DCE } from "./Report.js";
7
7
  import { concat } from "../../fable_modules/fable-library-js.5.17.2/String.js";
8
8
  import { forAll as forAll_1, concat as concat_1, head, tail, item as item_5, contains, filter as filter_1, map as map_1, ofArray, length, truncate, isEmpty, exists as exists_1, choose, cons, collect as collect_1, singleton, tryFind, fold, append, reverse, empty } from "../../fable_modules/fable-library-js.5.17.2/List.js";
@@ -78,8 +78,7 @@ function readInstantiatedMember(reader, contextNode, property, declaration) {
78
78
  return declaredMember;
79
79
  }
80
80
  else {
81
- const enclosingDeclaration = (contextNode.pos < 0) ? undefined : contextNode;
82
- const matchValue = checker.typeToTypeNode(instantiatedType, enclosingDeclaration, typeNodeBuilderFlags);
81
+ const matchValue = checker.typeToTypeNode(instantiatedType, enclosingDeclarationOf(contextNode), typeNodeBuilderFlags);
83
82
  if (matchValue != null) {
84
83
  const typeNode = matchValue;
85
84
  const previousContext = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_SyntheticContext"]();
@@ -609,7 +608,7 @@ function tryResolveDeferred(reader, typeNode) {
609
608
  }), typ);
610
609
  if (option_1 != null) {
611
610
  const resolved = option_1;
612
- option_3 = checker.typeToTypeNode(resolved, typeNode, typeNodeBuilderFlags);
611
+ option_3 = checker.typeToTypeNode(resolved, enclosingDeclarationOf(typeNode), typeNodeBuilderFlags);
613
612
  }
614
613
  else {
615
614
  option_3 = undefined;
@@ -851,7 +850,7 @@ export function UtilityType_readExclude(reader, typeReferenceNode) {
851
850
  }
852
851
  switch (matchResult) {
853
852
  case 0:
854
- return new GlueType(/* Union */ 7, [new GlueTypeUnion((matchValue_1 = typ.flags, ($007CHasTypeFlags$007C_$007C(1024, matchValue_1) != null) ? ((activePatternResult_4 = Type_StringLiteral_$007CString$007COther$007C(typ), (activePatternResult_4.tag === 1) ? (((item = Report_readerError_Z19516DCE("Exclude", "Expected a string literal", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 697), (objectArg = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"](), void (objectArg.push(item)))), empty())) : singleton(new GlueType(/* Literal */ 8, [new GlueLiteral(/* String */ 0, [activePatternResult_4.fields[0]])])))) : (($007CHasTypeFlags$007C_$007C(2048, matchValue_1) != null) ? ((activePatternResult_6 = Type_NumberLiteral_$007CInt$007CFloat$007COther$007C(typ), (activePatternResult_6.tag === 1) ? singleton(new GlueType(/* Literal */ 8, [new GlueLiteral(/* Float */ 2, [activePatternResult_6.fields[0]])])) : ((activePatternResult_6.tag === 2) ? (((item_1 = Report_readerError_Z19516DCE("Exclude", "Expected a number literal", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 712), (objectArg_1 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"](), void (objectArg_1.push(item_1)))), empty())) : singleton(new GlueType(/* Literal */ 8, [new GlueLiteral(/* Int */ 1, [activePatternResult_6.fields[0]])]))))) : choose((typ_1) => {
853
+ return new GlueType(/* Union */ 7, [new GlueTypeUnion((matchValue_1 = typ.flags, ($007CHasTypeFlags$007C_$007C(1024, matchValue_1) != null) ? ((activePatternResult_4 = Type_StringLiteral_$007CString$007COther$007C(typ), (activePatternResult_4.tag === 1) ? (((item = Report_readerError_Z19516DCE("Exclude", "Expected a string literal", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 696), (objectArg = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"](), void (objectArg.push(item)))), empty())) : singleton(new GlueType(/* Literal */ 8, [new GlueLiteral(/* String */ 0, [activePatternResult_4.fields[0]])])))) : (($007CHasTypeFlags$007C_$007C(2048, matchValue_1) != null) ? ((activePatternResult_6 = Type_NumberLiteral_$007CInt$007CFloat$007COther$007C(typ), (activePatternResult_6.tag === 1) ? singleton(new GlueType(/* Literal */ 8, [new GlueLiteral(/* Float */ 2, [activePatternResult_6.fields[0]])])) : ((activePatternResult_6.tag === 2) ? (((item_1 = Report_readerError_Z19516DCE("Exclude", "Expected a number literal", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 711), (objectArg_1 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"](), void (objectArg_1.push(item_1)))), empty())) : singleton(new GlueType(/* Literal */ 8, [new GlueLiteral(/* Int */ 1, [activePatternResult_6.fields[0]])]))))) : choose((typ_1) => {
855
854
  const matchValue_2 = typ_1.flags;
856
855
  if ($007CHasTypeFlags$007C_$007C(1024, matchValue_2) != null) {
857
856
  const literalType = typ_1;
@@ -863,7 +862,7 @@ export function UtilityType_readExclude(reader, typeReferenceNode) {
863
862
  case 1:
864
863
  return new GlueType(/* Literal */ 8, [new GlueLiteral(/* Float */ 2, [activePatternResult_9.fields[0]])]);
865
864
  case 2: {
866
- const item_2 = Report_readerError_Z19516DCE("Exclude", "Expected a number literal", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 739);
865
+ const item_2 = Report_readerError_Z19516DCE("Exclude", "Expected a number literal", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 738);
867
866
  const objectArg_2 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]();
868
867
  void (objectArg_2.push(item_2));
869
868
  return undefined;
@@ -958,7 +957,7 @@ export function UtilityType_readExclude(reader, typeReferenceNode) {
958
957
  return new GlueType(/* Primitive */ 3, [GluePrimitive.Any]);
959
958
  }
960
959
  else {
961
- const item_3 = Report_readerError_Z19516DCE("Exclude", "Was expecting the resolved type to be a literal or a union", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 795);
960
+ const item_3 = Report_readerError_Z19516DCE("Exclude", "Was expecting the resolved type to be a literal or a union", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 794);
962
961
  const objectArg_3 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]();
963
962
  void (objectArg_3.push(item_3));
964
963
  return new GlueType(/* Primitive */ 3, [GluePrimitive.Any]);
@@ -1279,7 +1278,7 @@ function UtilityType_withoutForeignTypeParameters(reader, bound, members) {
1279
1278
  export function UtilityType_readPartial(reader, typeReferenceNode) {
1280
1279
  const baseType = UtilityType_baseTypeOf(reader, value_6(typeReferenceNode.typeArguments)[0]);
1281
1280
  if (exists((typ) => (typ === baseType), reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_InProgress"]().Partials)) {
1282
- const item = Report_readerError_Z19516DCE("Partial", "Recursive Partial is not supported, defaulting to obj", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 1041);
1281
+ const item = Report_readerError_Z19516DCE("Partial", "Recursive Partial is not supported, defaulting to obj", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 1040);
1283
1282
  const objectArg = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]();
1284
1283
  void (objectArg.push(item));
1285
1284
  return new GlueType(/* Primitive */ 3, [GluePrimitive.Any]);
@@ -1332,7 +1331,7 @@ export function UtilityType_readPartial(reader, typeReferenceNode) {
1332
1331
  }
1333
1332
  default:
1334
1333
  if ($007CHasTypeFlags$007C_$007C(1, matchValue) != null) {
1335
- const item_1 = Report_readerError_Z19516DCE("partial inner type", "Was not able to resolve the inner type, and defaulting to any. If the base type is defined, in another file, please make sure to include it in the input files", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 1083);
1334
+ const item_1 = Report_readerError_Z19516DCE("partial inner type", "Was not able to resolve the inner type, and defaulting to any. If the base type is defined, in another file, please make sure to include it in the input files", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 1082);
1336
1335
  const objectArg_1 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]();
1337
1336
  void (objectArg_1.push(item_1));
1338
1337
  members = empty();
@@ -1441,7 +1440,7 @@ export function UtilityType_readOmitOrPick(reader, typeReferenceNode, keepListed
1441
1440
  const tryReadValueOfKeys = (typ) => {
1442
1441
  const activePatternResult_3 = Type_StringLiteral_$007CString$007COther$007C(typ);
1443
1442
  if (activePatternResult_3.tag === 1) {
1444
- const item = Report_readerError_Z19516DCE("keysToOmit", "Expected a string literal", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 1205);
1443
+ const item = Report_readerError_Z19516DCE("keysToOmit", "Expected a string literal", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 1204);
1445
1444
  const objectArg_1 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]();
1446
1445
  void (objectArg_1.push(item));
1447
1446
  return undefined;
@@ -1506,7 +1505,7 @@ export function UtilityType_readOmitOrPick(reader, typeReferenceNode, keepListed
1506
1505
  const filteredProperties = toList(filter((prop) => (keepListedKeys === contains_1(prop.name, keysToOmit, {
1507
1506
  Equals: (x, y) => (x === y),
1508
1507
  GetHashCode: (x) => (stringHash(x) | 0),
1509
- })), (matchValue_4 = baseType.flags, ($007CHasTypeFlags$007C_$007C(1, matchValue_4) != null) ? ((literalMembers != null) ? [] : (($007CHasTypeFlags$007C_$007C(1, matchValue_4) != null) ? (((item_1 = Report_readerError_Z19516DCE("omit base type", "Was not able to resolve the base type, and defaulting to any. If the base type is defined, in another file, please make sure to include it in the input files", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 1240), (objectArg_2 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"](), void (objectArg_2.push(item_1)))), [])) : ((objectArg_3 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"](), objectArg_3.getPropertiesOfType(baseType))))) : (($007CHasTypeFlags$007C_$007C(1, matchValue_4) != null) ? (((item_1 = Report_readerError_Z19516DCE("omit base type", "Was not able to resolve the base type, and defaulting to any. If the base type is defined, in another file, please make sure to include it in the input files", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 1240), (objectArg_2 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"](), void (objectArg_2.push(item_1)))), [])) : ((objectArg_3 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"](), objectArg_3.getPropertiesOfType(baseType)))))));
1508
+ })), (matchValue_4 = baseType.flags, ($007CHasTypeFlags$007C_$007C(1, matchValue_4) != null) ? ((literalMembers != null) ? [] : (($007CHasTypeFlags$007C_$007C(1, matchValue_4) != null) ? (((item_1 = Report_readerError_Z19516DCE("omit base type", "Was not able to resolve the base type, and defaulting to any. If the base type is defined, in another file, please make sure to include it in the input files", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 1239), (objectArg_2 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"](), void (objectArg_2.push(item_1)))), [])) : ((objectArg_3 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"](), objectArg_3.getPropertiesOfType(baseType))))) : (($007CHasTypeFlags$007C_$007C(1, matchValue_4) != null) ? (((item_1 = Report_readerError_Z19516DCE("omit base type", "Was not able to resolve the base type, and defaulting to any. If the base type is defined, in another file, please make sure to include it in the input files", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 1239), (objectArg_2 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"](), void (objectArg_2.push(item_1)))), [])) : ((objectArg_3 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"](), objectArg_3.getPropertiesOfType(baseType)))))));
1510
1509
  const isInProgress = exists((inProgress) => (inProgress === baseType), reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_InProgress"]().Expansions);
1511
1510
  const members_1 = isInProgress ? empty() : withInProgress(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_InProgress"]().Expansions, baseType, () => collect_1((property) => UtilityType_readPropertyMembers(reader, typeReferenceNode, property), filteredProperties));
1512
1511
  const defaults = defaultTypeArguments(reader, value_6(typeReferenceNode.typeArguments)[0]);
@@ -1598,7 +1597,7 @@ export function UtilityType_readReadonly(reader, typeReferenceNode) {
1598
1597
  }, unionType.types))])])]);
1599
1598
  }
1600
1599
  catch (matchValue_1) {
1601
- const item = Report_readerError_Z19516DCE("Readonly", "Unable to read the members of the union type", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 1364);
1600
+ const item = Report_readerError_Z19516DCE("Readonly", "Unable to read the members of the union type", typeReferenceNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 1363);
1602
1601
  const objectArg = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]();
1603
1602
  void (objectArg.push(item));
1604
1603
  return new GlueType(/* Primitive */ 3, [GluePrimitive.Any]);
@@ -2456,7 +2455,7 @@ export function readTypeNode(reader, typeNode) {
2456
2455
  const literalTypeNode = typeNode;
2457
2456
  const matchValue_2 = tryReadLiteral(checker, literalTypeNode.literal);
2458
2457
  if (matchValue_2 == null) {
2459
- throw new Exception(Report_readerError_Z19516DCE("type node - literal type", "Could not read literal type", typeNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 2239));
2458
+ throw new Exception(Report_readerError_Z19516DCE("type node - literal type", "Could not read literal type", typeNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 2238));
2460
2459
  }
2461
2460
  else {
2462
2461
  return new GlueType(/* Literal */ 8, [matchValue_2]);
@@ -2471,7 +2470,7 @@ export function readTypeNode(reader, typeNode) {
2471
2470
  case 234:
2472
2471
  return readExpressionWithTypeArguments(reader, typeNode);
2473
2472
  default: {
2474
- const item = Report_readerError_Z19516DCE("type node", concat("Unsupported kind ", TypeScript_Ts_SyntaxKind__SyntaxKind_get_Name(typeNode.kind)), typeNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 2365);
2473
+ const item = Report_readerError_Z19516DCE("type node", concat("Unsupported kind ", TypeScript_Ts_SyntaxKind__SyntaxKind_get_Name(typeNode.kind)), typeNode, "/_//src/Glutinum.Converter/Reader/TypeNode.fs", 2364);
2475
2474
  const objectArg = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]();
2476
2475
  void (objectArg.push(item));
2477
2476
  return new GlueType(/* Primitive */ 3, [GluePrimitive.Any]);
@@ -253,14 +253,29 @@ export function entityNameText(node) {
253
253
  }
254
254
 
255
255
  /**
256
- * Identity of an anonymous type, a node synthesized by `typeToTypeNode` has none
256
+ * A node synthesized by `typeToTypeNode` has a negative position, or in TypeScript 6 a
257
+ * position without a source file; the checker throws when given one as enclosing declaration
257
258
  */
258
- export function typeLiteralId(node) {
259
+ export function enclosingDeclarationOf(node) {
259
260
  if ((node.pos < 0) ? true : Operators_IsNull(node.getSourceFile())) {
260
261
  return undefined;
261
262
  }
262
263
  else {
263
- return `${normalizePath(node.getSourceFile().fileName)}:${node.pos}`;
264
+ return node;
265
+ }
266
+ }
267
+
268
+ /**
269
+ * Identity of an anonymous type, a node synthesized by `typeToTypeNode` has none
270
+ */
271
+ export function typeLiteralId(node) {
272
+ let node_1;
273
+ const option_1 = enclosingDeclarationOf(node);
274
+ if (option_1 != null) {
275
+ return (node_1 = option_1, `${normalizePath(node_1.getSourceFile().fileName)}:${node_1.pos}`);
276
+ }
277
+ else {
278
+ return undefined;
264
279
  }
265
280
  }
266
281