@glutinum/cli 0.14.1 → 1.0.0-beta.10

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 (64) 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 +154 -69
  6. package/dist/Glutinum.Converter/Generate.js +44 -23
  7. package/dist/Glutinum.Converter/GlueAST.js +122 -74
  8. package/dist/Glutinum.Converter/Hosting.js +892 -0
  9. package/dist/Glutinum.Converter/Merge.js +469 -301
  10. package/dist/Glutinum.Converter/Packages.js +403 -77
  11. package/dist/Glutinum.Converter/Printer.js +455 -388
  12. package/dist/Glutinum.Converter/Read.js +366 -104
  13. package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +9 -9
  14. package/dist/Glutinum.Converter/Reader/ConditionalTypeNode.js +90 -0
  15. package/dist/Glutinum.Converter/Reader/Declaration.js +24 -30
  16. package/dist/Glutinum.Converter/Reader/Deferred.js +706 -0
  17. package/dist/Glutinum.Converter/Reader/Documentation.js +56 -67
  18. package/dist/Glutinum.Converter/Reader/ExportAssignment.js +105 -38
  19. package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +52 -55
  20. package/dist/Glutinum.Converter/Reader/ExpressionWithTypeArguments.js +59 -0
  21. package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +28 -16
  22. package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +46 -45
  23. package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +48 -5
  24. package/dist/Glutinum.Converter/Reader/IntersectionTypeNode.js +178 -0
  25. package/dist/Glutinum.Converter/Reader/MappedTypeNode.js +82 -4
  26. package/dist/Glutinum.Converter/Reader/MemberTypes.js +126 -0
  27. package/dist/Glutinum.Converter/Reader/ModuleDeclaration.js +55 -7
  28. package/dist/Glutinum.Converter/Reader/Node.js +23 -26
  29. package/dist/Glutinum.Converter/Reader/Parameters.js +39 -30
  30. package/dist/Glutinum.Converter/Reader/TypeAliasDeclaration.js +5 -5
  31. package/dist/Glutinum.Converter/Reader/TypeNode.js +410 -1545
  32. package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +78 -51
  33. package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +116 -71
  34. package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +25 -7
  35. package/dist/Glutinum.Converter/Reader/Types.js +296 -16
  36. package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +21 -34
  37. package/dist/Glutinum.Converter/Reader/UtilityType.js +811 -0
  38. package/dist/Glutinum.Converter/Reader/Utils.js +584 -148
  39. package/dist/Glutinum.Converter/Reader/VariableStatement.js +2 -3
  40. package/dist/Glutinum.Converter/Transform.js +2971 -6875
  41. package/dist/Glutinum.Converter/Transformer/AnyFunctionOverloads.js +116 -0
  42. package/dist/Glutinum.Converter/Transformer/CallableProperties.js +454 -0
  43. package/dist/Glutinum.Converter/Transformer/Comment.js +136 -0
  44. package/dist/Glutinum.Converter/Transformer/Conditionals.js +1087 -0
  45. package/dist/Glutinum.Converter/Transformer/Context.js +678 -0
  46. package/dist/Glutinum.Converter/Transformer/Enum.js +80 -0
  47. package/dist/Glutinum.Converter/Transformer/Exports.js +704 -0
  48. package/dist/Glutinum.Converter/Transformer/Heritage.js +493 -0
  49. package/dist/Glutinum.Converter/Transformer/KeyOfMaps.js +488 -0
  50. package/dist/Glutinum.Converter/Transformer/ParamObjectCandidate.js +460 -0
  51. package/dist/Glutinum.Converter/Transformer/TypeParameter.js +219 -0
  52. package/dist/Glutinum.Converter/Transformer/TypeParameters.js +448 -0
  53. package/dist/Glutinum.Converter/Transformer/UnionOverloads.js +356 -0
  54. package/dist/Glutinum.Converter/Transformer/Utils.js +341 -0
  55. package/dist/Glutinum.Converter/TypeScript.Extensions.js +193 -211
  56. package/dist/Glutinum.Converter/Utils/Naming.js +7 -0
  57. package/dist/Glutinum.Converter/Utils/String.js +15 -4
  58. package/dist/Program.js +107 -232
  59. package/package.json +4 -3
  60. package/dist/Glutinum.Converter/TypeScript.js +0 -12
  61. package/src/Glutinum.Converter/js/bootstrap.js +0 -123
  62. package/src/Glutinum.Converter/js/host.js +0 -144
  63. package/src/Glutinum.Converter/js/npm.js +0 -137
  64. package/src/Glutinum.Converter/js/resolve.js +0 -402
@@ -0,0 +1,59 @@
1
+
2
+ import { defaultArg, orElse } from "../../fable_modules/fable-library-js.5.17.2/Option.js";
3
+ import { Operators_IsNull } from "../../fable_modules/fable-library-js.5.17.2/FSharp.Core.js";
4
+ import { resolvedBaseTypeArguments, typeNodeBuilderFlags, readTypeArguments, landingOf, crossesNamespace, modulePathForSymbol, isLibraryName, resolveValueAlias, knownExternalTypeNames, isExternalToPackages, declaredName, getFullNameOrEmpty, isFromEs5Lib } from "./Utils.js";
5
+ import { readPick, readOmit } from "./UtilityType.js";
6
+ import { FSharpSet__Contains } from "../../fable_modules/fable-library-js.5.17.2/Set.js";
7
+ import { GlueTypeReference, GlueType } from "../GlueAST.js";
8
+ import { sanitizeTypeName } from "../Utils/Naming.js";
9
+ import { map, isEmpty, empty } from "../../fable_modules/fable-library-js.5.17.2/List.js";
10
+ import { toList } from "../../fable_modules/fable-library-js.5.17.2/Seq.js";
11
+
12
+ export function readExpressionWithTypeArguments(reader, typeNode) {
13
+ let symbol, symbol_2, symbol_3, symbol_4, matchValue_2, option_4, symbol_6, matchValue_3, ofAlias, matchValue_4, matchValue_5, alias, written, option_6;
14
+ const checker = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"]();
15
+ const expression = typeNode;
16
+ const typ = checker.getTypeFromTypeNode(expression);
17
+ const symbolOpt = orElse(orElse(typ.aliasSymbol, Operators_IsNull(typ.symbol) ? undefined : typ.symbol), checker.getSymbolAtLocation(expression.expression));
18
+ const isFromEs5 = isFromEs5Lib(symbolOpt);
19
+ const matchValue = getFullNameOrEmpty(checker, expression.expression);
20
+ let matchResult;
21
+ if (isFromEs5) {
22
+ switch (matchValue) {
23
+ case "Omit": {
24
+ matchResult = 0;
25
+ break;
26
+ }
27
+ case "Pick": {
28
+ matchResult = 1;
29
+ break;
30
+ }
31
+ default:
32
+ matchResult = 2;
33
+ }
34
+ }
35
+ else {
36
+ matchResult = 2;
37
+ }
38
+ switch (matchResult) {
39
+ case 0:
40
+ return readOmit(reader, expression);
41
+ case 1:
42
+ return readPick(reader, expression);
43
+ default: {
44
+ const isQualified = expression.expression.kind === 212;
45
+ const name = (symbolOpt != null) ? (((symbol = symbolOpt, symbol.name === "default")) ? ((symbol_2 = symbolOpt, defaultArg(declaredName(symbol_2), symbol_2.name))) : ((!isFromEs5) ? ((symbol_3 = symbolOpt, symbol_3.name)) : (isQualified ? expression.expression.name.text : expression.expression.getText()))) : (isQualified ? expression.expression.name.text : expression.expression.getText());
46
+ const isExternal = isExternalToPackages(checker, reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_PackageContext"](), symbolOpt);
47
+ if (((symbolOpt == null) ? false : ((symbol_4 = symbolOpt, (symbol_4.name === "__type") ? true : (symbol_4.name === "__object")))) ? true : ((isExternal && !FSharpSet__Contains(knownExternalTypeNames, name)) && !(isFromEs5 && (name === "Partial")))) {
48
+ return GlueType.Discard;
49
+ }
50
+ else {
51
+ return new GlueType(/* TypeReference */ 13, [new GlueTypeReference((name.indexOf(".") >= 0) ? name : sanitizeTypeName(name), (matchValue_2 = ((option_4 = symbolOpt, (option_4 != null) ? resolveValueAlias(checker, option_4) : undefined)), (matchValue_2 == null) ? getFullNameOrEmpty(checker, expression.expression) : ((symbol_6 = matchValue_2, checker.getFullyQualifiedName(symbol_6)))), isLibraryName(reader, name) ? empty() : modulePathForSymbol(checker, reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_PackageContext"](), isQualified ? true : crossesNamespace(checker, reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_PackageContext"](), symbolOpt, landingOf(reader, expression)), symbolOpt), (matchValue_3 = readTypeArguments(reader, expression), isEmpty(matchValue_3) ? ((ofAlias = (((matchValue_4 = checker.getSymbolAtLocation(expression.expression), (matchValue_5 = typ.aliasSymbol, (matchValue_4 != null) && ((matchValue_5 != null) && ((alias = matchValue_5, (written = matchValue_4, !(written === alias)))))))) ? defaultArg((option_6 = typ.aliasTypeArguments, (option_6 != null) ? toList(option_6) : undefined), empty()) : empty()), map((argument) => {
52
+ const typNode = checker.typeToTypeNode(argument, undefined, typeNodeBuilderFlags);
53
+ return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNodeZ64B23DD2"](typNode);
54
+ }, isEmpty(ofAlias) ? resolvedBaseTypeArguments(checker, expression) : ofAlias))) : matchValue_3), (isFromEs5 ? true : isExternal) ? true : isLibraryName(reader, name))]);
55
+ }
56
+ }
57
+ }
58
+ }
59
+
@@ -1,10 +1,9 @@
1
1
 
2
2
  import { exists } from "../../fable_modules/fable-library-js.5.17.2/Seq.js";
3
- import { tryReadKeyOfConstraint, ModifierUtil_HasModifier_Z687DC302 } from "./Utils.js";
3
+ import { tryReadKeyOfConstraint, isDefaultInExportList, ModifierUtil_HasModifier_742AC9D } from "./Utils.js";
4
4
  import { Exception } from "../../fable_modules/fable-library-js.5.17.2/Util.js";
5
5
  import { Report_readerError_Z19516DCE } from "./Report.js";
6
6
  import { mapIndexed } from "../../fable_modules/fable-library-js.5.17.2/List.js";
7
- import { item } from "../../fable_modules/fable-library-js.5.17.2/Array.js";
8
7
  import { value } from "../../fable_modules/fable-library-js.5.17.2/Option.js";
9
8
  import { GlueType, GlueFunctionDeclaration, GlueTypeParameter } from "../GlueAST.js";
10
9
 
@@ -12,32 +11,45 @@ export function readFunctionDeclaration(reader, declaration) {
12
11
  let isDeclared;
13
12
  const matchValue = declaration.modifiers;
14
13
  isDeclared = ((matchValue == null) ? false : exists((modifier) => (modifier.kind === 138), matchValue));
15
- const isDefaultExport = ModifierUtil_HasModifier_Z687DC302(declaration.modifiers, 90);
16
- let name_1;
17
- const matchValue_1 = declaration.name;
18
- if (matchValue_1 == null) {
14
+ let isDefaultExport;
15
+ if (ModifierUtil_HasModifier_742AC9D(declaration.modifiers, 90)) {
16
+ isDefaultExport = true;
17
+ }
18
+ else {
19
+ const matchValue_1 = declaration.name;
20
+ if (matchValue_1 == null) {
21
+ isDefaultExport = false;
22
+ }
23
+ else {
24
+ const name = matchValue_1;
25
+ isDefaultExport = isDefaultInExportList(declaration, name.getText());
26
+ }
27
+ }
28
+ let name_2;
29
+ const matchValue_2 = declaration.name;
30
+ if (matchValue_2 == null) {
19
31
  if (isDefaultExport) {
20
- name_1 = "defaultExport";
32
+ name_2 = "defaultExport";
21
33
  }
22
34
  else {
23
- throw new Exception(Report_readerError_Z19516DCE("function declaration", "Missing name", declaration, "/_//src/Glutinum.Converter/Reader/FunctionDeclaration.fs", 29));
35
+ throw new Exception(Report_readerError_Z19516DCE("function declaration", "Missing name", declaration, "/_//src/Glutinum.Converter/Reader/FunctionDeclaration.fs", 34));
24
36
  }
25
37
  }
26
38
  else {
27
- const name = matchValue_1;
28
- name_1 = name.getText();
39
+ const name_1 = matchValue_2;
40
+ name_2 = name_1.getText();
29
41
  }
30
- const functionDeclaration = new GlueFunctionDeclaration(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadDocumentationFromSignature61B89E55"](declaration), isDeclared, name_1, reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNodeZ64B23DD2"](declaration.type), reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadParametersZ17143B5B"](declaration.parameters), mapIndexed((index, typeParameter) => {
31
- const matchValue_2 = tryReadKeyOfConstraint(reader, item(index, value(declaration.typeParameters)));
32
- if (matchValue_2 == null) {
42
+ const functionDeclaration = new GlueFunctionDeclaration(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadDocumentationFromSignature61B89E55"](declaration), isDeclared, name_2, reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNodeZ64B23DD2"](declaration.type), reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadParameters716C1F42"](declaration.parameters), mapIndexed((index, typeParameter) => {
43
+ const matchValue_3 = tryReadKeyOfConstraint(reader, value(declaration.typeParameters)[index]);
44
+ if (matchValue_3 == null) {
33
45
  return typeParameter;
34
46
  }
35
47
  else {
36
- return new GlueTypeParameter(typeParameter.Name, matchValue_2, typeParameter.Default);
48
+ return new GlueTypeParameter(typeParameter.Name, matchValue_3, typeParameter.Default);
37
49
  }
38
- }, reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeParameters4088FB9E"](declaration.typeParameters)));
50
+ }, reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeParameters4BD418D9"](declaration.typeParameters)));
39
51
  if (isDefaultExport) {
40
- return new GlueType(/* ExportDefault */ 24, [new GlueType(/* FunctionDeclaration */ 6, [functionDeclaration])]);
52
+ return new GlueType(/* ExportDefault */ 25, [new GlueType(/* FunctionDeclaration */ 6, [functionDeclaration])]);
41
53
  }
42
54
  else {
43
55
  return new GlueType(/* FunctionDeclaration */ 6, [functionDeclaration]);
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { GluePrimitive, GlueType, GlueIndexedAccessType } from "../GlueAST.js";
3
- import { $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";
@@ -10,56 +10,60 @@ export function readIndexedAccessType(reader, declaration) {
10
10
  const idxNodeType = declaration.indexType;
11
11
  const withIndexType = (indexType) => (new GlueType(/* IndexedAccessType */ 10, [new GlueIndexedAccessType(indexType, reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](declaration.objectType))]));
12
12
  const node = declaration;
13
- const matchValue_2 = idxNodeType.kind;
14
- let matchResult;
15
- switch (matchValue_2) {
16
- case 150: {
17
- matchResult = 1;
18
- break;
13
+ const tryTypeToTypeNode = (typ, flags) => {
14
+ try {
15
+ return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"]().typeToTypeNode(typ, enclosingDeclarationOf(node), flags);
16
+ }
17
+ catch (matchValue) {
18
+ return undefined;
19
19
  }
20
+ };
21
+ const matchValue_3 = idxNodeType.kind;
22
+ let matchResult;
23
+ switch (matchValue_3) {
24
+ case 150:
20
25
  case 154:
21
- case 183: {
22
- matchResult = 4;
26
+ case 184: {
27
+ matchResult = 3;
23
28
  break;
24
29
  }
25
- case 193: {
26
- matchResult = 5;
30
+ case 194: {
31
+ matchResult = 4;
27
32
  break;
28
33
  }
29
- case 198: {
34
+ case 199: {
30
35
  matchResult = 0;
31
36
  break;
32
37
  }
33
- case 201: {
38
+ case 202: {
34
39
  if (node.pos >= 0) {
35
- matchResult = 2;
40
+ matchResult = 1;
36
41
  }
37
42
  else {
38
- matchResult = 3;
43
+ matchResult = 2;
39
44
  }
40
45
  break;
41
46
  }
42
47
  default:
43
- matchResult = 6;
48
+ matchResult = 5;
44
49
  }
45
50
  switch (matchResult) {
46
51
  case 0: {
47
- let matchValue_3;
52
+ let matchValue_4;
48
53
  if (node.pos < 0) {
49
- matchValue_3 = undefined;
54
+ matchValue_4 = undefined;
50
55
  }
51
56
  else {
52
57
  const checker = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"]();
53
- const typ = checker.getTypeAtLocation(node);
54
- const matchValue = typ.flags;
55
- if ($007CHasTypeFlags$007C_$007C(1048576, matchValue) != null) {
56
- const flags = 1 | 16384;
57
- const matchValue_1 = checker.typeToTypeNode(typ, node, flags);
58
+ const typ_1 = checker.getTypeAtLocation(node);
59
+ const matchValue_1 = typ_1.flags;
60
+ if ($007CHasTypeFlags$007C_$007C(134217728, matchValue_1) != null) {
61
+ const matchValue_2 = tryTypeToTypeNode(typ_1, typeNodeBuilderFlags);
58
62
  let matchResult_1, typeNode_1;
59
- if (matchValue_1 != null) {
60
- if ((typeNode = matchValue_1, typeNode.kind === 192)) {
63
+ if (matchValue_2 != null) {
64
+ if ((typeNode = matchValue_2, typeNode.kind === 193)) {
61
65
  matchResult_1 = 0;
62
- typeNode_1 = matchValue_1;
66
+ typeNode_1 = matchValue_2;
63
67
  }
64
68
  else {
65
69
  matchResult_1 = 1;
@@ -70,56 +74,53 @@ export function readIndexedAccessType(reader, declaration) {
70
74
  }
71
75
  switch (matchResult_1) {
72
76
  case 0: {
73
- matchValue_3 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](typeNode_1);
77
+ matchValue_4 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](typeNode_1);
74
78
  break;
75
79
  }
76
80
  default:
77
- matchValue_3 = undefined;
81
+ matchValue_4 = undefined;
78
82
  }
79
83
  }
80
84
  else {
81
- matchValue_3 = undefined;
85
+ matchValue_4 = undefined;
82
86
  }
83
87
  }
84
- if (matchValue_3 == null) {
88
+ if (matchValue_4 == null) {
85
89
  const typeOperatorNode = declaration.indexType;
86
90
  return withIndexType(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeOperatorNodeZ6830FC33"](typeOperatorNode));
87
91
  }
88
92
  else {
89
- return matchValue_3;
93
+ return matchValue_4;
90
94
  }
91
95
  }
92
- case 1:
93
- return withIndexType(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](idxNodeType));
94
- case 2: {
96
+ case 1: {
95
97
  const checker_1 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"]();
96
98
  const objectType = checker_1.getTypeAtLocation(declaration.objectType);
97
99
  const key = idxNodeType.literal.text;
98
- const flags_1 = 1 | 16384;
99
- const matchValue_4 = checker_1.getPropertyOfType(objectType, key);
100
- if (matchValue_4 == null) {
100
+ const matchValue_5 = checker_1.getPropertyOfType(objectType, key);
101
+ if (matchValue_5 == null) {
101
102
  return new GlueType(/* Primitive */ 3, [GluePrimitive.Any]);
102
103
  }
103
104
  else {
104
- const property = matchValue_4;
105
- const matchValue_5 = checker_1.typeToTypeNode(checker_1.getTypeOfSymbol(property), node, flags_1);
106
- if (matchValue_5 == null) {
105
+ const property = matchValue_5;
106
+ const matchValue_6 = tryTypeToTypeNode(checker_1.getTypeOfSymbol(property), typeNodeBuilderFlags);
107
+ if (matchValue_6 == null) {
107
108
  return new GlueType(/* Primitive */ 3, [GluePrimitive.Any]);
108
109
  }
109
110
  else {
110
- const typeNode_2 = matchValue_5;
111
+ const typeNode_2 = matchValue_6;
111
112
  return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](typeNode_2);
112
113
  }
113
114
  }
114
115
  }
115
- case 3:
116
+ case 2:
116
117
  return new GlueType(/* Primitive */ 3, [GluePrimitive.Any]);
117
- case 4:
118
+ case 3:
118
119
  return withIndexType(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](idxNodeType));
119
- case 5:
120
+ case 4:
120
121
  return withIndexType(GlueType.Discard);
121
122
  default: {
122
- const warning = Report_readerError_Z19516DCE("readIndexedAccessType", concat("Unsupported node kind ", TypeScript_Ts_SyntaxKind__SyntaxKind_get_Name(matchValue_2)), idxNodeType, "/_//src/Glutinum.Converter/Reader/IndexedAccessType.fs", 88);
123
+ const warning = Report_readerError_Z19516DCE("readIndexedAccessType", concat("Unsupported node kind ", TypeScript_Ts_SyntaxKind__SyntaxKind_get_Name(matchValue_3)), idxNodeType, "/_//src/Glutinum.Converter/Reader/IndexedAccessType.fs", 87);
123
124
  void (reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]().push(warning));
124
125
  return withIndexType(GlueType.Discard);
125
126
  }
@@ -1,11 +1,12 @@
1
1
 
2
- import { tryItem, tryPick, mapIndexed, filter, forAll, cons, map, collect, empty } from "../../fable_modules/fable-library-js.5.17.2/List.js";
2
+ import { isEmpty, tryItem, tryPick, mapIndexed, filter, forAll, cons, map, collect, empty } from "../../fable_modules/fable-library-js.5.17.2/List.js";
3
3
  import { readHeritageClauses, getFullNameOrEmpty, otherFileInterfaceDeclarations, mainDeclaration } from "./Utils.js";
4
4
  import { toList } from "../../fable_modules/fable-library-js.5.17.2/Seq.js";
5
5
  import { defaultArg } from "../../fable_modules/fable-library-js.5.17.2/Option.js";
6
- import { GlueInterface, GlueTypeParameter } from "../GlueAST.js";
6
+ import { GlueReExport, GlueType, GlueInterface, GlueTypeParameter } from "../GlueAST.js";
7
7
  import { List_distinct } from "../../fable_modules/fable-library-js.5.17.2/Seq2.js";
8
8
  import { safeHash, equals } from "../../fable_modules/fable-library-js.5.17.2/Util.js";
9
+ import { PackageContext__TryFindExternalModulePath_Z721C83C5 } from "./Types.js";
9
10
 
10
11
  export function readInterfaceDeclaration(reader, declaration) {
11
12
  let option_1;
@@ -41,7 +42,7 @@ export function readInterfaceDeclaration(reader, declaration) {
41
42
  }
42
43
  const members = collect((declaration_1) => map((declaration_2) => reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadDeclaration61B89E55"](declaration_2), toList(declaration_1.members)), cons(declaration, otherDeclarations));
43
44
  let typeParameters;
44
- const own = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeParameters4088FB9E"](declaration.typeParameters);
45
+ const own = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeParameters4BD418D9"](declaration.typeParameters);
45
46
  if (forAll((typeParameter) => (typeParameter.Default != null), own)) {
46
47
  typeParameters = own;
47
48
  }
@@ -53,8 +54,8 @@ export function readInterfaceDeclaration(reader, declaration) {
53
54
  }
54
55
  else {
55
56
  const symbol_1 = matchValue_1;
56
- othersDefaults = map((other_1) => reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeParameters4088FB9E"](other_1.typeParameters), filter((other) => {
57
- if (other.kind === 264) {
57
+ othersDefaults = map((other_1) => reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeParameters4BD418D9"](other_1.typeParameters), filter((other) => {
58
+ if (other.kind === 265) {
58
59
  return !(other === declaration);
59
60
  }
60
61
  else {
@@ -85,3 +86,45 @@ export function readInterfaceDeclaration(reader, declaration) {
85
86
  }));
86
87
  }
87
88
 
89
+ /**
90
+ * <c>interface Blob extends _Blob {}</c> of <c>@types/node</c> redeclares a type of the DOM lib,
91
+ * with no member of its own: the declaration of the external binding is the one carrying the API
92
+ */
93
+ export function tryReadExternalRedeclaration(reader, declaration, glueInterface) {
94
+ let option_1;
95
+ if (!isEmpty(glueInterface.Members)) {
96
+ return undefined;
97
+ }
98
+ else {
99
+ const matchValue = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_PackageContext"]();
100
+ const matchValue_1 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"]().getSymbolAtLocation(declaration.name);
101
+ let matchResult, packageContext, symbol;
102
+ if (matchValue != null) {
103
+ if (matchValue_1 != null) {
104
+ matchResult = 0;
105
+ packageContext = matchValue;
106
+ symbol = matchValue_1;
107
+ }
108
+ else {
109
+ matchResult = 1;
110
+ }
111
+ }
112
+ else {
113
+ matchResult = 1;
114
+ }
115
+ switch (matchResult) {
116
+ case 0: {
117
+ const option_4 = tryPick((other) => PackageContext__TryFindExternalModulePath_Z721C83C5(packageContext, other.getSourceFile().fileName), defaultArg((option_1 = symbol.declarations, (option_1 != null) ? toList(option_1) : undefined), empty()));
118
+ if (option_4 != null) {
119
+ return new GlueType(/* ReExport */ 32, [new GlueReExport(glueInterface.Name, new GlueType(/* Interface */ 1, [glueInterface]), option_4)]);
120
+ }
121
+ else {
122
+ return undefined;
123
+ }
124
+ }
125
+ default:
126
+ return undefined;
127
+ }
128
+ }
129
+ }
130
+
@@ -0,0 +1,178 @@
1
+
2
+ import { Exception, stringHash, structuralHash, equals, disposeSafe } from "../../fable_modules/fable-library-js.5.17.2/Util.js";
3
+ import { head, tail, append, forAll as forAll_1, filter, empty, exists as exists_1, collect, isEmpty, map, concat, choose } from "../../fable_modules/fable-library-js.5.17.2/List.js";
4
+ import { readInstantiatedMember, readPropertyWithoutDeclaration, IntersectionTypePropertyResult } from "./MemberTypes.js";
5
+ import { item } from "../../fable_modules/fable-library-js.5.17.2/Array.js";
6
+ import { filter as filter_1, exists, toList, forAll } from "../../fable_modules/fable-library-js.5.17.2/Seq.js";
7
+ import { List_distinctBy, List_distinct } from "../../fable_modules/fable-library-js.5.17.2/Seq2.js";
8
+ import { withInProgress, typeNodeBuilderFlags } from "./Utils.js";
9
+ import { GluePrimitive, GlueType } from "../GlueAST.js";
10
+
11
+ function readIntersectionConstituents(reader, typeNode) {
12
+ let matchValue;
13
+ const checker = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"]();
14
+ const intersectionTypeNode = typeNode;
15
+ const unionOrIntersectionType = checker.getTypeAtLocation(intersectionTypeNode);
16
+ void (reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_InProgress"]().Intersections.push(unionOrIntersectionType));
17
+ const _guard = {
18
+ Dispose() {
19
+ reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_InProgress"]().Intersections.splice(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_InProgress"]().Intersections.length - 1, 1);
20
+ },
21
+ };
22
+ try {
23
+ const properties_1 = choose((property_1) => {
24
+ const matchValue_1 = property_1.declarations;
25
+ if (matchValue_1 == null) {
26
+ return new IntersectionTypePropertyResult(/* WithoutDeclaration */ 1, [property_1]);
27
+ }
28
+ else {
29
+ const declarations = matchValue_1;
30
+ if (declarations.length === 1) {
31
+ return new IntersectionTypePropertyResult(/* Single */ 0, [property_1, item(0, declarations)]);
32
+ }
33
+ else if (forAll((declaration) => {
34
+ if (declaration.kind === 172) {
35
+ return true;
36
+ }
37
+ else {
38
+ return declaration.kind === 173;
39
+ }
40
+ }, declarations)) {
41
+ return new IntersectionTypePropertyResult(/* WithoutDeclaration */ 1, [property_1]);
42
+ }
43
+ else {
44
+ return IntersectionTypePropertyResult.ForceAny;
45
+ }
46
+ }
47
+ }, unionOrIntersectionType.isUnion() ? List_distinct(concat(map((arg) => toList(checker.getPropertiesOfType(arg)), toList(unionOrIntersectionType.types))), {
48
+ Equals: equals,
49
+ GetHashCode: (x) => (structuralHash(x) | 0),
50
+ }) : ((matchValue = toList(unionOrIntersectionType.getProperties()), isEmpty(matchValue) ? ((intersectionTypeNode.pos >= 0) ? List_distinctBy((property) => property.name, collect((constituent) => {
51
+ let type_1;
52
+ return toList((type_1 = checker.getTypeAtLocation(constituent), checker.getPropertiesOfType(type_1)));
53
+ }, toList(intersectionTypeNode.types)), {
54
+ Equals: (x_1, y_1) => (x_1 === y_1),
55
+ GetHashCode: (x_1) => (stringHash(x_1) | 0),
56
+ }) : matchValue) : matchValue)));
57
+ const intersectsATypeQuery = exists((constituent_1) => (constituent_1.kind === 187), intersectionTypeNode.types);
58
+ const everyConstituentIsAReference = forAll((constituent_2) => (constituent_2.kind === 184), intersectionTypeNode.types);
59
+ const hasUnsupportedProperties = intersectsATypeQuery ? true : exists_1((property_2) => {
60
+ switch (property_2.tag) {
61
+ case 1:
62
+ return false;
63
+ case 0:
64
+ if (everyConstituentIsAReference) {
65
+ return property_2.fields[1].kind === 175;
66
+ }
67
+ else {
68
+ return false;
69
+ }
70
+ default:
71
+ return true;
72
+ }
73
+ }, properties_1);
74
+ const callSignatures = unionOrIntersectionType.isUnion() ? empty() : choose((signature) => {
75
+ const synthesized = checker.signatureToSignatureDeclaration(signature, 180, typeNode, typeNodeBuilderFlags);
76
+ if (synthesized == null) {
77
+ return undefined;
78
+ }
79
+ else {
80
+ const declaration_2 = synthesized;
81
+ declaration_2.parent = typeNode;
82
+ const previousContext = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_SyntheticContext"]();
83
+ reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.set_SyntheticContext"](declaration_2);
84
+ try {
85
+ return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadDeclaration61B89E55"](declaration_2);
86
+ }
87
+ finally {
88
+ reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.set_SyntheticContext"](previousContext);
89
+ }
90
+ }
91
+ }, toList(checker.getSignaturesOfType(unionOrIntersectionType, 0)));
92
+ if (hasUnsupportedProperties) {
93
+ const references = map((constituent_3) => {
94
+ if (constituent_3.kind === 184) {
95
+ return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](constituent_3);
96
+ }
97
+ else {
98
+ return GlueType.Discard;
99
+ }
100
+ }, toList(intersectionTypeNode.types));
101
+ const literalMembers = collect((constituent_4) => {
102
+ if (constituent_4.kind === 188) {
103
+ const matchValue_2 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](constituent_4);
104
+ if (matchValue_2.tag === 22) {
105
+ return matchValue_2.fields[0].Members;
106
+ }
107
+ else {
108
+ return empty();
109
+ }
110
+ }
111
+ else {
112
+ return empty();
113
+ }
114
+ }, toList(intersectionTypeNode.types));
115
+ const inheritable = filter((reference) => !equals(reference, GlueType.Discard), references);
116
+ return (!isEmpty(inheritable) && forAll_1((_arg) => {
117
+ if (_arg.tag === 13) {
118
+ return true;
119
+ }
120
+ else {
121
+ return false;
122
+ }
123
+ }, inheritable)) ? (new GlueType(/* IntersectionOfReferences */ 21, [inheritable, literalMembers])) : (new GlueType(/* Primitive */ 3, [GluePrimitive.Any]));
124
+ }
125
+ else {
126
+ return new GlueType(/* IntersectionType */ 20, [append(withInProgress(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_InProgress"]().Landing, typeNode, () => choose((_arg_1) => {
127
+ switch (_arg_1.tag) {
128
+ case 1:
129
+ return readPropertyWithoutDeclaration(reader, typeNode, _arg_1.fields[0]);
130
+ case 2:
131
+ throw new Exception("Should not happen here");
132
+ default:
133
+ return readInstantiatedMember(reader, typeNode, _arg_1.fields[0], _arg_1.fields[1]);
134
+ }
135
+ }, properties_1)), append(callSignatures, collect((constituent_5) => {
136
+ if (constituent_5.kind === 188) {
137
+ return map((declaration_4) => reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadDeclaration61B89E55"](declaration_4), filter((element) => (element.kind === 182), toList(constituent_5.members)));
138
+ }
139
+ else {
140
+ return empty();
141
+ }
142
+ }, toList(intersectionTypeNode.types))))]);
143
+ }
144
+ }
145
+ finally {
146
+ disposeSafe(_guard);
147
+ }
148
+ }
149
+
150
+ /**
151
+ * `DateArg<Date> & {}` is `DateArg<Date>`, the empty type literal only bars `null`
152
+ */
153
+ export function readIntersectionType(reader, typeNode) {
154
+ const constituents = toList(filter_1((arg) => {
155
+ let constituent, this$;
156
+ return !((constituent = arg, (constituent.kind === 188) && (((this$ = constituent.members, ~~this$.length)) === 0)));
157
+ }, typeNode.types));
158
+ let matchResult, single;
159
+ if (!isEmpty(constituents)) {
160
+ if (isEmpty(tail(constituents))) {
161
+ matchResult = 0;
162
+ single = head(constituents);
163
+ }
164
+ else {
165
+ matchResult = 1;
166
+ }
167
+ }
168
+ else {
169
+ matchResult = 1;
170
+ }
171
+ switch (matchResult) {
172
+ case 0:
173
+ return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](single);
174
+ default:
175
+ return readIntersectionConstituents(reader, typeNode);
176
+ }
177
+ }
178
+