@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.
- package/README.md +16 -0
- package/dist/Glutinum.Converter/Abbreviations.js +9 -32
- package/dist/Glutinum.Converter/DelegateExtensions.js +378 -0
- package/dist/Glutinum.Converter/FreeTypeParameters.js +211 -0
- package/dist/Glutinum.Converter/FsharpAST.js +154 -69
- package/dist/Glutinum.Converter/Generate.js +44 -23
- package/dist/Glutinum.Converter/GlueAST.js +122 -74
- package/dist/Glutinum.Converter/Hosting.js +892 -0
- package/dist/Glutinum.Converter/Merge.js +469 -301
- package/dist/Glutinum.Converter/Packages.js +403 -77
- package/dist/Glutinum.Converter/Printer.js +455 -388
- package/dist/Glutinum.Converter/Read.js +366 -104
- package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +9 -9
- package/dist/Glutinum.Converter/Reader/ConditionalTypeNode.js +90 -0
- package/dist/Glutinum.Converter/Reader/Declaration.js +24 -30
- package/dist/Glutinum.Converter/Reader/Deferred.js +706 -0
- package/dist/Glutinum.Converter/Reader/Documentation.js +56 -67
- package/dist/Glutinum.Converter/Reader/ExportAssignment.js +105 -38
- package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +52 -55
- package/dist/Glutinum.Converter/Reader/ExpressionWithTypeArguments.js +59 -0
- package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +28 -16
- package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +46 -45
- package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +48 -5
- package/dist/Glutinum.Converter/Reader/IntersectionTypeNode.js +178 -0
- package/dist/Glutinum.Converter/Reader/MappedTypeNode.js +82 -4
- package/dist/Glutinum.Converter/Reader/MemberTypes.js +126 -0
- package/dist/Glutinum.Converter/Reader/ModuleDeclaration.js +55 -7
- package/dist/Glutinum.Converter/Reader/Node.js +23 -26
- package/dist/Glutinum.Converter/Reader/Parameters.js +39 -30
- package/dist/Glutinum.Converter/Reader/TypeAliasDeclaration.js +5 -5
- package/dist/Glutinum.Converter/Reader/TypeNode.js +410 -1545
- package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +78 -51
- package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +116 -71
- package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +25 -7
- package/dist/Glutinum.Converter/Reader/Types.js +296 -16
- package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +21 -34
- package/dist/Glutinum.Converter/Reader/UtilityType.js +811 -0
- package/dist/Glutinum.Converter/Reader/Utils.js +584 -148
- package/dist/Glutinum.Converter/Reader/VariableStatement.js +2 -3
- package/dist/Glutinum.Converter/Transform.js +2971 -6875
- package/dist/Glutinum.Converter/Transformer/AnyFunctionOverloads.js +116 -0
- package/dist/Glutinum.Converter/Transformer/CallableProperties.js +454 -0
- package/dist/Glutinum.Converter/Transformer/Comment.js +136 -0
- package/dist/Glutinum.Converter/Transformer/Conditionals.js +1087 -0
- package/dist/Glutinum.Converter/Transformer/Context.js +678 -0
- package/dist/Glutinum.Converter/Transformer/Enum.js +80 -0
- package/dist/Glutinum.Converter/Transformer/Exports.js +704 -0
- package/dist/Glutinum.Converter/Transformer/Heritage.js +493 -0
- package/dist/Glutinum.Converter/Transformer/KeyOfMaps.js +488 -0
- package/dist/Glutinum.Converter/Transformer/ParamObjectCandidate.js +460 -0
- package/dist/Glutinum.Converter/Transformer/TypeParameter.js +219 -0
- package/dist/Glutinum.Converter/Transformer/TypeParameters.js +448 -0
- package/dist/Glutinum.Converter/Transformer/UnionOverloads.js +356 -0
- package/dist/Glutinum.Converter/Transformer/Utils.js +341 -0
- package/dist/Glutinum.Converter/TypeScript.Extensions.js +193 -211
- package/dist/Glutinum.Converter/Utils/Naming.js +7 -0
- package/dist/Glutinum.Converter/Utils/String.js +15 -4
- package/dist/Program.js +107 -232
- package/package.json +4 -3
- package/dist/Glutinum.Converter/TypeScript.js +0 -12
- package/src/Glutinum.Converter/js/bootstrap.js +0 -123
- package/src/Glutinum.Converter/js/host.js +0 -144
- package/src/Glutinum.Converter/js/npm.js +0 -137
- package/src/Glutinum.Converter/js/resolve.js +0 -402
|
@@ -1,22 +1,43 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { FSharpRef, Record } from "../fable_modules/fable-library-js.5.17.2/Types.js";
|
|
3
|
+
import { record_type, tuple_type, list_type, class_type, string_type } from "../fable_modules/fable-library-js.5.17.2/Reflection.js";
|
|
4
|
+
import { FSharpClass, FSharpModule, FSharpInterface, FSharpStaticMemberInfo, FSharpMember, FSharpMemberInfo, FSharpTypeModule_children, FSharpFunctionType, FSharpParameter, FSharpTypeModule_mapChildren, FSharpTypeReference, FSharpType, FSharpType_$reflection } from "./FsharpAST.js";
|
|
5
|
+
import { ofList, FSharpMap__TryFind, tryFind, ofSeq, empty } from "../fable_modules/fable-library-js.5.17.2/Map.js";
|
|
6
|
+
import { Exception, safeHash, equals, compareArrays, arrayHash, equalArrays, defaultOf, int32ToString, disposeSafe, getEnumerator, comparePrimitives } from "../fable_modules/fable-library-js.5.17.2/Util.js";
|
|
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.17.2/List.js";
|
|
4
8
|
import { concat, join } from "../fable_modules/fable-library-js.5.17.2/String.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { addToDict, addToSet, tryGetValue
|
|
8
|
-
import { value } from "../fable_modules/fable-library-js.5.17.2/Option.js";
|
|
9
|
-
import { FSharpRef } from "../fable_modules/fable-library-js.5.17.2/Types.js";
|
|
10
|
-
import { FSharpSet__Contains, FSharpSet__get_IsEmpty, ofSeq } from "../fable_modules/fable-library-js.5.17.2/Set.js";
|
|
9
|
+
import { map as map_1 } from "../fable_modules/fable-library-js.5.17.2/Seq.js";
|
|
10
|
+
import { FSharpSet__get_IsEmpty, ofSeq as ofSeq_1, empty as empty_2, FSharpSet__Contains } from "../fable_modules/fable-library-js.5.17.2/Set.js";
|
|
11
|
+
import { addToDict, getItemFromDict, addToSet, tryGetValue } from "../fable_modules/fable-library-js.5.17.2/MapUtil.js";
|
|
11
12
|
import { List_distinctBy, List_distinct, List_groupBy } from "../fable_modules/fable-library-js.5.17.2/Seq2.js";
|
|
12
13
|
import { FSharpChoice$3 } from "../fable_modules/fable-library-js.5.17.2/Choice.js";
|
|
13
14
|
import { contains, setItem, item } from "../fable_modules/fable-library-js.5.17.2/Array.js";
|
|
15
|
+
import { HashSet } from "../fable_modules/fable-library-js.5.17.2/MutableSet.js";
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The type aliases of the output, two references are the same type when they alias the same one
|
|
19
|
+
*/
|
|
20
|
+
export class Aliases extends Record {
|
|
21
|
+
constructor(Targets, Generic) {
|
|
22
|
+
super();
|
|
23
|
+
this.Targets = Targets;
|
|
24
|
+
this.Generic = Generic;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function Aliases_$reflection() {
|
|
29
|
+
return record_type("Glutinum.Converter.Merge.Aliases", [], Aliases, () => [["Targets", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, FSharpType_$reflection()])], ["Generic", class_type("Microsoft.FSharp.Collections.FSharpMap`2", [string_type, tuple_type(list_type(string_type), FSharpType_$reflection())])]]);
|
|
30
|
+
}
|
|
16
31
|
|
|
17
|
-
|
|
32
|
+
export function Aliases_get_Empty() {
|
|
33
|
+
return new Aliases(empty({
|
|
34
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
35
|
+
}), empty({
|
|
36
|
+
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
18
39
|
|
|
19
|
-
function collectAliases(path, types) {
|
|
40
|
+
function collectAliases(aliasTargets, genericAliasTargets, path, types) {
|
|
20
41
|
const enumerator = getEnumerator(types);
|
|
21
42
|
try {
|
|
22
43
|
while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
|
|
@@ -62,7 +83,7 @@ function collectAliases(path, types) {
|
|
|
62
83
|
break;
|
|
63
84
|
}
|
|
64
85
|
case 4: {
|
|
65
|
-
collectAliases(append(path, singleton(typ.fields[0].Name)), typ.fields[0].Types);
|
|
86
|
+
collectAliases(aliasTargets, genericAliasTargets, append(path, singleton(typ.fields[0].Name)), typ.fields[0].Types);
|
|
66
87
|
break;
|
|
67
88
|
}
|
|
68
89
|
default:
|
|
@@ -75,57 +96,47 @@ function collectAliases(path, types) {
|
|
|
75
96
|
}
|
|
76
97
|
}
|
|
77
98
|
|
|
99
|
+
/**
|
|
100
|
+
* The aliases the types declare
|
|
101
|
+
*/
|
|
102
|
+
export function aliasesOf(types) {
|
|
103
|
+
const aliasTargets = new Map([]);
|
|
104
|
+
const genericAliasTargets = new Map([]);
|
|
105
|
+
collectAliases(aliasTargets, genericAliasTargets, empty_1(), types);
|
|
106
|
+
return new Aliases(ofSeq(map_1((_arg) => {
|
|
107
|
+
const activePatternResult = _arg;
|
|
108
|
+
return [activePatternResult[0], activePatternResult[1]];
|
|
109
|
+
}, aliasTargets), {
|
|
110
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
111
|
+
}), ofSeq(map_1((_arg_1) => {
|
|
112
|
+
const activePatternResult_1 = _arg_1;
|
|
113
|
+
return [activePatternResult_1[0], activePatternResult_1[1]];
|
|
114
|
+
}, genericAliasTargets), {
|
|
115
|
+
Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
|
|
78
119
|
function substitute(substitutions, typ) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const matchValue = tryFind(typ.fields[0], substitutions);
|
|
83
|
-
if (matchValue == null) {
|
|
84
|
-
return typ;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
return matchValue;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
case 11: {
|
|
91
|
-
const typeReference = typ.fields[0];
|
|
92
|
-
return new FSharpType(/* TypeReference */ 11, [new FSharpTypeReference(typeReference.Name, typeReference.FullName, typeReference.ModulePath, map(substitute_1, typeReference.TypeArguments), typeReference.Type)]);
|
|
93
|
-
}
|
|
94
|
-
case 3:
|
|
95
|
-
return new FSharpType(/* Option */ 3, [substitute_1(typ.fields[0])]);
|
|
96
|
-
case 14:
|
|
97
|
-
return new FSharpType(/* ResizeArray */ 14, [substitute_1(typ.fields[0])]);
|
|
98
|
-
case 19:
|
|
99
|
-
return new FSharpType(/* JSApi */ 19, [new FSharpJSApi(substitute_1(typ.fields[0].fields[0]))]);
|
|
100
|
-
case 12:
|
|
101
|
-
return new FSharpType(/* Tuple */ 12, [map(substitute_1, typ.fields[0])]);
|
|
102
|
-
case 16: {
|
|
103
|
-
const functionType = typ.fields[0];
|
|
104
|
-
return new FSharpType(/* Function */ 16, [new FSharpFunctionType(map((parameter) => (new FSharpParameter(parameter.Attributes, parameter.Name, parameter.IsOptional, substitute_1(parameter.Type), parameter.OriginalGlueMember)), functionType.Parameters), substitute_1(functionType.ReturnType))]);
|
|
105
|
-
}
|
|
106
|
-
case 1: {
|
|
107
|
-
const unionInfo = typ.fields[0];
|
|
108
|
-
return new FSharpType(/* Union */ 1, [new FSharpUnion(unionInfo.Attributes, unionInfo.Name, map((_arg) => {
|
|
109
|
-
switch (_arg.tag) {
|
|
110
|
-
case 1:
|
|
111
|
-
return new FSharpUnionCase(/* Typed */ 1, [substitute_1(_arg.fields[0])]);
|
|
112
|
-
case 2:
|
|
113
|
-
return new FSharpUnionCase(/* Field */ 2, [_arg.fields[0], substitute_1(_arg.fields[1])]);
|
|
114
|
-
default:
|
|
115
|
-
return _arg;
|
|
116
|
-
}
|
|
117
|
-
}, unionInfo.Cases), unionInfo.IsOptional, unionInfo.TypeParameters, unionInfo.Constants)]);
|
|
118
|
-
}
|
|
119
|
-
default:
|
|
120
|
+
if (typ.tag === 13) {
|
|
121
|
+
const matchValue = tryFind(typ.fields[0], substitutions);
|
|
122
|
+
if (matchValue == null) {
|
|
120
123
|
return typ;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
return matchValue;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
return FSharpTypeModule_mapChildren((typ_3) => substitute(substitutions, typ_3), typ);
|
|
121
131
|
}
|
|
122
132
|
}
|
|
123
133
|
|
|
124
|
-
function tryGenericAliasTarget(typeReference) {
|
|
134
|
+
function tryGenericAliasTarget(aliases, typeReference) {
|
|
125
135
|
let tupledArg;
|
|
126
136
|
const arity = "`" + int32ToString(length(typeReference.TypeArguments));
|
|
127
|
-
|
|
128
|
-
const
|
|
137
|
+
let option_1;
|
|
138
|
+
const matchValue = FSharpMap__TryFind(aliases.Generic, join(".", append(typeReference.ModulePath, singleton(typeReference.Name))) + arity);
|
|
139
|
+
option_1 = ((matchValue == null) ? (isEmpty_1(typeReference.ModulePath) ? FSharpMap__TryFind(aliases.Generic, typeReference.Name + arity) : undefined) : matchValue);
|
|
129
140
|
if (option_1 != null) {
|
|
130
141
|
return (tupledArg = option_1, substitute(ofList(zip(tupledArg[0], typeReference.TypeArguments), {
|
|
131
142
|
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
@@ -136,106 +147,131 @@ function tryGenericAliasTarget(typeReference) {
|
|
|
136
147
|
}
|
|
137
148
|
}
|
|
138
149
|
|
|
139
|
-
function
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
matchResult = 0;
|
|
149
|
-
typeReference_2 = typ.fields[0];
|
|
150
|
-
}
|
|
151
|
-
else if ((typeReference_1 = typ.fields[0], ((depth < 8) && !isEmpty_1(typeReference_1.TypeArguments)) && (tryGenericAliasTarget(typeReference_1) != null))) {
|
|
152
|
-
matchResult = 1;
|
|
153
|
-
typeReference_3 = typ.fields[0];
|
|
150
|
+
function tryAliasTarget(aliases, typeReference) {
|
|
151
|
+
if (!isEmpty_1(typeReference.TypeArguments)) {
|
|
152
|
+
return tryGenericAliasTarget(aliases, typeReference);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
const matchValue = FSharpMap__TryFind(aliases.Targets, join(".", append(typeReference.ModulePath, singleton(typeReference.Name))));
|
|
156
|
+
if (matchValue == null) {
|
|
157
|
+
if (isEmpty_1(typeReference.ModulePath)) {
|
|
158
|
+
return FSharpMap__TryFind(aliases.Targets, typeReference.Name);
|
|
154
159
|
}
|
|
155
160
|
else {
|
|
156
|
-
|
|
157
|
-
typeReference_4 = typ.fields[0];
|
|
161
|
+
return undefined;
|
|
158
162
|
}
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
case 3: {
|
|
162
|
-
matchResult = 3;
|
|
163
|
-
typ_2 = typ.fields[0];
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
case 14: {
|
|
167
|
-
matchResult = 4;
|
|
168
|
-
typ_3 = typ.fields[0];
|
|
169
|
-
break;
|
|
170
163
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
typ_4 = typ.fields[0].fields[0];
|
|
174
|
-
break;
|
|
164
|
+
else {
|
|
165
|
+
return matchValue;
|
|
175
166
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function $007CAliasTarget$007C_$007C(aliases, typ) {
|
|
171
|
+
if (typ.tag === 11) {
|
|
172
|
+
return tryAliasTarget(aliases, typ.fields[0]);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function signatureTypeAt(aliases, depth, typ) {
|
|
180
|
+
let signatureType_1;
|
|
181
|
+
const depth_1 = (depth + 1) | 0;
|
|
182
|
+
signatureType_1 = ((typ_1) => signatureTypeAt(aliases, depth_1, typ_1));
|
|
183
|
+
let matchResult, target_1;
|
|
184
|
+
const activePatternResult = $007CAliasTarget$007C_$007C(aliases, typ);
|
|
185
|
+
if (activePatternResult != null) {
|
|
186
|
+
if (depth < 8) {
|
|
187
|
+
matchResult = 0;
|
|
188
|
+
target_1 = activePatternResult;
|
|
180
189
|
}
|
|
181
|
-
|
|
182
|
-
matchResult =
|
|
183
|
-
functionType = typ.fields[0];
|
|
184
|
-
break;
|
|
190
|
+
else {
|
|
191
|
+
matchResult = 1;
|
|
185
192
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
matchResult = 1;
|
|
196
|
+
}
|
|
197
|
+
switch (matchResult) {
|
|
198
|
+
case 0:
|
|
199
|
+
return signatureType_1(target_1);
|
|
200
|
+
default: {
|
|
201
|
+
let matchResult_1, typeArgument, typeReference, functionType, typ_2;
|
|
202
|
+
switch (typ.tag) {
|
|
203
|
+
case 11: {
|
|
204
|
+
if (typ.fields[0].Name === "ResizeArray") {
|
|
205
|
+
if (!isEmpty_1(typ.fields[0].TypeArguments)) {
|
|
206
|
+
if (isEmpty_1(tail(typ.fields[0].TypeArguments))) {
|
|
207
|
+
matchResult_1 = 0;
|
|
208
|
+
typeArgument = head(typ.fields[0].TypeArguments);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
matchResult_1 = 1;
|
|
212
|
+
typeReference = typ.fields[0];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
matchResult_1 = 1;
|
|
217
|
+
typeReference = typ.fields[0];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
matchResult_1 = 1;
|
|
222
|
+
typeReference = typ.fields[0];
|
|
223
|
+
}
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
case 16: {
|
|
227
|
+
matchResult_1 = 2;
|
|
228
|
+
functionType = typ.fields[0];
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
case 8: {
|
|
232
|
+
if (typ.fields[0].tag === 6) {
|
|
233
|
+
matchResult_1 = 3;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
matchResult_1 = 4;
|
|
237
|
+
typ_2 = typ;
|
|
238
|
+
}
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
default: {
|
|
242
|
+
matchResult_1 = 4;
|
|
243
|
+
typ_2 = typ;
|
|
244
|
+
}
|
|
189
245
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
246
|
+
switch (matchResult_1) {
|
|
247
|
+
case 0:
|
|
248
|
+
return new FSharpType(/* ResizeArray */ 14, [signatureType_1(typeArgument)]);
|
|
249
|
+
case 1:
|
|
250
|
+
return new FSharpType(/* TypeReference */ 11, [new FSharpTypeReference((typeReference.Name === "JS.Uint8ClampedArray") ? "JS.Uint8Array" : typeReference.Name, "", typeReference.ModulePath, map(signatureType_1, typeReference.TypeArguments), FSharpType.Discard)]);
|
|
251
|
+
case 2:
|
|
252
|
+
return new FSharpType(/* Function */ 16, [new FSharpFunctionType(map((parameter) => (new FSharpParameter(parameter.Attributes, parameter.Name, parameter.IsOptional, signatureType_1(parameter.Type), undefined)), functionType.Parameters), signatureType_1(functionType.ReturnType))]);
|
|
253
|
+
case 3:
|
|
254
|
+
return FSharpType.Object$;
|
|
255
|
+
default:
|
|
256
|
+
return FSharpTypeModule_mapChildren(signatureType_1, typ_2);
|
|
193
257
|
}
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
default: {
|
|
197
|
-
matchResult = 9;
|
|
198
|
-
typ_5 = typ;
|
|
199
258
|
}
|
|
200
259
|
}
|
|
201
|
-
switch (matchResult) {
|
|
202
|
-
case 0: {
|
|
203
|
-
const fullPath = join(".", append(typeReference_2.ModulePath, singleton(typeReference_2.Name)));
|
|
204
|
-
return signatureType_1(aliasTargets.has(fullPath) ? getItemFromDict(aliasTargets, fullPath) : getItemFromDict(aliasTargets, typeReference_2.Name));
|
|
205
|
-
}
|
|
206
|
-
case 1:
|
|
207
|
-
return signatureType_1(value(tryGenericAliasTarget(typeReference_3)));
|
|
208
|
-
case 2:
|
|
209
|
-
return new FSharpType(/* TypeReference */ 11, [new FSharpTypeReference((typeReference_4.Name === "JS.Uint8ClampedArray") ? "JS.Uint8Array" : typeReference_4.Name, "", typeReference_4.ModulePath, map(signatureType_1, typeReference_4.TypeArguments), FSharpType.Discard)]);
|
|
210
|
-
case 3:
|
|
211
|
-
return new FSharpType(/* Option */ 3, [signatureType_1(typ_2)]);
|
|
212
|
-
case 4:
|
|
213
|
-
return new FSharpType(/* ResizeArray */ 14, [signatureType_1(typ_3)]);
|
|
214
|
-
case 5:
|
|
215
|
-
return new FSharpType(/* JSApi */ 19, [new FSharpJSApi(signatureType_1(typ_4))]);
|
|
216
|
-
case 6:
|
|
217
|
-
return new FSharpType(/* Tuple */ 12, [map(signatureType_1, types)]);
|
|
218
|
-
case 7:
|
|
219
|
-
return new FSharpType(/* Function */ 16, [new FSharpFunctionType(map((parameter) => (new FSharpParameter(parameter.Attributes, parameter.Name, parameter.IsOptional, signatureType_1(parameter.Type), undefined)), functionType.Parameters), signatureType_1(functionType.ReturnType))]);
|
|
220
|
-
case 8:
|
|
221
|
-
return FSharpType.Object$;
|
|
222
|
-
default:
|
|
223
|
-
return typ_5;
|
|
224
|
-
}
|
|
225
260
|
}
|
|
226
261
|
|
|
227
|
-
export function signatureType(typ) {
|
|
228
|
-
return signatureTypeAt(0, typ);
|
|
262
|
+
export function signatureType(aliases, typ) {
|
|
263
|
+
return signatureTypeAt(aliases, 0, typ);
|
|
229
264
|
}
|
|
230
265
|
|
|
231
|
-
function canonicalTypeParameters(names, typ) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
266
|
+
function canonicalTypeParameters(erased, names, typ) {
|
|
267
|
+
if (typ.tag === 13) {
|
|
268
|
+
if (FSharpSet__Contains(erased, typ.fields[0])) {
|
|
269
|
+
return FSharpType.Object$;
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
236
272
|
let matchValue;
|
|
237
273
|
let outArg = defaultOf();
|
|
238
|
-
matchValue = [tryGetValue(names,
|
|
274
|
+
matchValue = [tryGetValue(names, typ.fields[0], new FSharpRef(() => outArg, (v) => {
|
|
239
275
|
outArg = v;
|
|
240
276
|
})), outArg];
|
|
241
277
|
if (matchValue[0]) {
|
|
@@ -243,152 +279,76 @@ function canonicalTypeParameters(names, typ) {
|
|
|
243
279
|
}
|
|
244
280
|
else {
|
|
245
281
|
const canonicalName_1 = `T${names.size}`;
|
|
246
|
-
names.set(
|
|
282
|
+
names.set(typ.fields[0], canonicalName_1);
|
|
247
283
|
return new FSharpType(/* TypeParameter */ 13, [canonicalName_1]);
|
|
248
284
|
}
|
|
249
285
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
case 3:
|
|
255
|
-
return new FSharpType(/* Option */ 3, [canonical(typ.fields[0])]);
|
|
256
|
-
case 14:
|
|
257
|
-
return new FSharpType(/* ResizeArray */ 14, [canonical(typ.fields[0])]);
|
|
258
|
-
case 19:
|
|
259
|
-
return new FSharpType(/* JSApi */ 19, [new FSharpJSApi(canonical(typ.fields[0].fields[0]))]);
|
|
260
|
-
case 1: {
|
|
261
|
-
const unionInfo = typ.fields[0];
|
|
262
|
-
return new FSharpType(/* Union */ 1, [new FSharpUnion(unionInfo.Attributes, unionInfo.Name, map((_arg) => {
|
|
263
|
-
switch (_arg.tag) {
|
|
264
|
-
case 1:
|
|
265
|
-
return new FSharpUnionCase(/* Typed */ 1, [canonical(_arg.fields[0])]);
|
|
266
|
-
case 2:
|
|
267
|
-
return new FSharpUnionCase(/* Field */ 2, [_arg.fields[0], canonical(_arg.fields[1])]);
|
|
268
|
-
default:
|
|
269
|
-
return _arg;
|
|
270
|
-
}
|
|
271
|
-
}, unionInfo.Cases), unionInfo.IsOptional, unionInfo.TypeParameters, unionInfo.Constants)]);
|
|
272
|
-
}
|
|
273
|
-
case 12:
|
|
274
|
-
return new FSharpType(/* Tuple */ 12, [map(canonical, typ.fields[0])]);
|
|
275
|
-
case 16: {
|
|
276
|
-
const functionType = typ.fields[0];
|
|
277
|
-
return new FSharpType(/* Function */ 16, [new FSharpFunctionType(map((parameter) => (new FSharpParameter(parameter.Attributes, parameter.Name, parameter.IsOptional, canonical(parameter.Type), parameter.OriginalGlueMember)), functionType.Parameters), canonical(functionType.ReturnType))]);
|
|
278
|
-
}
|
|
279
|
-
default:
|
|
280
|
-
return typ;
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
return FSharpTypeModule_mapChildren((typ_1) => canonicalTypeParameters(erased, names, typ_1), typ);
|
|
281
289
|
}
|
|
282
290
|
}
|
|
283
291
|
|
|
284
|
-
export function
|
|
292
|
+
export function parametersSignatureWith(aliases, erased, parameters) {
|
|
285
293
|
const names = new Map([]);
|
|
286
|
-
return map((parameter) => [canonicalTypeParameters(names, signatureType(parameter.Type)), parameter.IsOptional], parameters);
|
|
294
|
+
return map((parameter) => [canonicalTypeParameters(erased, names, signatureType(aliases, parameter.Type)), parameter.IsOptional], parameters);
|
|
287
295
|
}
|
|
288
296
|
|
|
289
|
-
function
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
break;
|
|
303
|
-
}
|
|
304
|
-
case 3: {
|
|
305
|
-
matchResult = 2;
|
|
306
|
-
typ_1 = typ.fields[0];
|
|
307
|
-
break;
|
|
308
|
-
}
|
|
309
|
-
case 14: {
|
|
310
|
-
matchResult = 2;
|
|
311
|
-
typ_1 = typ.fields[0];
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
case 19: {
|
|
315
|
-
matchResult = 2;
|
|
316
|
-
typ_1 = typ.fields[0].fields[0];
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
case 1: {
|
|
320
|
-
matchResult = 3;
|
|
321
|
-
break;
|
|
322
|
-
}
|
|
323
|
-
case 12: {
|
|
324
|
-
matchResult = 4;
|
|
325
|
-
break;
|
|
326
|
-
}
|
|
327
|
-
case 16: {
|
|
328
|
-
matchResult = 5;
|
|
329
|
-
break;
|
|
330
|
-
}
|
|
331
|
-
default:
|
|
332
|
-
matchResult = 6;
|
|
333
|
-
}
|
|
334
|
-
switch (matchResult) {
|
|
335
|
-
case 0:
|
|
336
|
-
return true;
|
|
337
|
-
case 1:
|
|
338
|
-
return exists(mentionsTypeParameter, typ.fields[0].TypeArguments);
|
|
339
|
-
case 2: {
|
|
340
|
-
typ_mut = typ_1;
|
|
341
|
-
continue mentionsTypeParameter;
|
|
342
|
-
}
|
|
343
|
-
case 3:
|
|
344
|
-
return exists((_arg) => {
|
|
345
|
-
let matchResult_1, typ_2;
|
|
346
|
-
switch (_arg.tag) {
|
|
347
|
-
case 1: {
|
|
348
|
-
matchResult_1 = 0;
|
|
349
|
-
typ_2 = _arg.fields[0];
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
case 2: {
|
|
353
|
-
matchResult_1 = 0;
|
|
354
|
-
typ_2 = _arg.fields[1];
|
|
355
|
-
break;
|
|
356
|
-
}
|
|
357
|
-
default:
|
|
358
|
-
matchResult_1 = 1;
|
|
359
|
-
}
|
|
360
|
-
switch (matchResult_1) {
|
|
361
|
-
case 0:
|
|
362
|
-
return mentionsTypeParameter(typ_2);
|
|
363
|
-
default:
|
|
364
|
-
return false;
|
|
365
|
-
}
|
|
366
|
-
}, typ.fields[0].Cases);
|
|
367
|
-
case 4:
|
|
368
|
-
return exists(mentionsTypeParameter, typ.fields[0]);
|
|
369
|
-
case 5: {
|
|
370
|
-
const functionType = typ.fields[0];
|
|
371
|
-
if (mentionsTypeParameter(functionType.ReturnType)) {
|
|
372
|
-
return true;
|
|
373
|
-
}
|
|
374
|
-
else {
|
|
375
|
-
return exists((parameter) => mentionsTypeParameter(parameter.Type), functionType.Parameters);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
default:
|
|
379
|
-
return false;
|
|
380
|
-
}
|
|
381
|
-
break;
|
|
297
|
+
export function parametersSignature(aliases, parameters) {
|
|
298
|
+
return parametersSignatureWith(aliases, empty_2({
|
|
299
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
300
|
+
}), parameters);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function distinguishableTypeParameters(typeParameters, parameters) {
|
|
304
|
+
const namesOf = (typ) => {
|
|
305
|
+
if (typ.tag === 13) {
|
|
306
|
+
return singleton(typ.fields[0]);
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
return collect(namesOf, FSharpTypeModule_children(typ));
|
|
382
310
|
}
|
|
383
311
|
};
|
|
384
|
-
|
|
385
|
-
|
|
312
|
+
const mentioned = ofSeq_1(collect((parameter) => namesOf(parameter.Type), parameters), {
|
|
313
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
314
|
+
});
|
|
315
|
+
return length(filter((_arg) => {
|
|
316
|
+
if (_arg.tag === 0) {
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
return !FSharpSet__Contains(mentioned, _arg.fields[0].Name);
|
|
321
|
+
}
|
|
322
|
+
}, typeParameters)) | 0;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function ownTypeParameterNames(typeParameters) {
|
|
326
|
+
return ofSeq_1(choose((_arg) => {
|
|
327
|
+
if (_arg.tag === 0) {
|
|
328
|
+
return undefined;
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
return _arg.fields[0].Name;
|
|
332
|
+
}
|
|
333
|
+
}, typeParameters), {
|
|
334
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function withoutOption(typ) {
|
|
339
|
+
if (typ.tag === 3) {
|
|
340
|
+
return typ.fields[0];
|
|
386
341
|
}
|
|
387
342
|
else {
|
|
388
|
-
return
|
|
343
|
+
return typ;
|
|
389
344
|
}
|
|
390
345
|
}
|
|
391
346
|
|
|
347
|
+
function signatureKey(aliases, typeParameters, parameters) {
|
|
348
|
+
const erased = ownTypeParameterNames(typeParameters);
|
|
349
|
+
return [distinguishableTypeParameters(typeParameters, parameters), map((arg) => withoutOption(arg[0]), parametersSignatureWith(aliases, erased, parameters))];
|
|
350
|
+
}
|
|
351
|
+
|
|
392
352
|
function withParameterlessOverloads(members) {
|
|
393
353
|
const isAllOptional = (parameters) => {
|
|
394
354
|
if (!isEmpty_1(parameters)) {
|
|
@@ -398,7 +358,7 @@ function withParameterlessOverloads(members) {
|
|
|
398
358
|
return false;
|
|
399
359
|
}
|
|
400
360
|
};
|
|
401
|
-
const ambiguous =
|
|
361
|
+
const ambiguous = ofSeq_1(map((tuple) => tuple[0], filter((tupledArg_1) => {
|
|
402
362
|
const group = tupledArg_1[1];
|
|
403
363
|
if (length(filter((tupledArg_2) => tupledArg_2[2], group)) >= 2) {
|
|
404
364
|
return !exists((tupledArg_3) => tupledArg_3[3], group);
|
|
@@ -429,7 +389,7 @@ function withParameterlessOverloads(members) {
|
|
|
429
389
|
return members;
|
|
430
390
|
}
|
|
431
391
|
else {
|
|
432
|
-
const preferred =
|
|
392
|
+
const preferred = ofSeq_1(map((tupledArg_5) => (head(sortBy((tupledArg_6) => [!tupledArg_6[0], tupledArg_6[1]], map((tuple_2) => tuple_2[1], tupledArg_5[1]), {
|
|
433
393
|
Compare: (x_3, y_3) => (compareArrays(x_3, y_3) | 0),
|
|
434
394
|
}))[1] | 0), List_groupBy((tuple_1) => tuple_1[0], choose((tupledArg_4) => {
|
|
435
395
|
let info_2, info_3;
|
|
@@ -504,9 +464,9 @@ function withParameterlessOverloads(members) {
|
|
|
504
464
|
}
|
|
505
465
|
switch (matchResult_1) {
|
|
506
466
|
case 0:
|
|
507
|
-
return ofArray([fsharpMember_2, new FSharpMember(/* Method */ 0, [new FSharpMemberInfo(info_8.Attributes, info_8.Name, info_8.OriginalName,
|
|
467
|
+
return ofArray([fsharpMember_2, new FSharpMember(/* Method */ 0, [new FSharpMemberInfo(info_8.Attributes, info_8.Name, info_8.OriginalName, empty_1(), empty_1(), info_8.Type, info_8.IsOptional, info_8.IsStatic, info_8.Accessor, info_8.Accessibility, info_8.XmlDoc, info_8.Body)])]);
|
|
508
468
|
case 1:
|
|
509
|
-
return ofArray([fsharpMember_2, new FSharpMember(/* StaticMember */ 2, [new FSharpStaticMemberInfo(info_9.Attributes, info_9.Name, info_9.OriginalName,
|
|
469
|
+
return ofArray([fsharpMember_2, new FSharpMember(/* StaticMember */ 2, [new FSharpStaticMemberInfo(info_9.Attributes, info_9.Name, info_9.OriginalName, empty_1(), empty_1(), info_9.Type, info_9.IsOptional, info_9.Accessor, info_9.Accessibility, info_9.XmlDoc)])]);
|
|
510
470
|
default:
|
|
511
471
|
return singleton(fsharpMember_2);
|
|
512
472
|
}
|
|
@@ -514,16 +474,88 @@ function withParameterlessOverloads(members) {
|
|
|
514
474
|
}
|
|
515
475
|
}
|
|
516
476
|
|
|
517
|
-
|
|
518
|
-
const
|
|
519
|
-
|
|
477
|
+
function withoutSubsumedOverloads(aliases, members) {
|
|
478
|
+
const signatureOf = (fsharpMember) => {
|
|
479
|
+
switch (fsharpMember.tag) {
|
|
480
|
+
case 2: {
|
|
481
|
+
const info_1 = fsharpMember.fields[0];
|
|
482
|
+
return [[info_1.Name, false, true], info_1.TypeParameters, parametersSignature(aliases, info_1.Parameters), info_1.Type];
|
|
483
|
+
}
|
|
484
|
+
case 1:
|
|
485
|
+
return undefined;
|
|
486
|
+
default: {
|
|
487
|
+
const info = fsharpMember.fields[0];
|
|
488
|
+
return [[info.Name, true, info.IsStatic], info.TypeParameters, parametersSignature(aliases, info.Parameters), info.Type];
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
return filter((candidate) => {
|
|
493
|
+
const matchValue_3 = filter((other) => {
|
|
494
|
+
const matchValue = signatureOf(other);
|
|
495
|
+
const matchValue_1 = signatureOf(candidate);
|
|
496
|
+
let matchResult, longKey, longParameters, longType, longTypeParameters, shortKey, shortParameters, shortType, shortTypeParameters;
|
|
497
|
+
if (matchValue != null) {
|
|
498
|
+
if (matchValue_1 != null) {
|
|
499
|
+
matchResult = 0;
|
|
500
|
+
longKey = matchValue[0];
|
|
501
|
+
longParameters = matchValue[2];
|
|
502
|
+
longType = matchValue[3];
|
|
503
|
+
longTypeParameters = matchValue[1];
|
|
504
|
+
shortKey = matchValue_1[0];
|
|
505
|
+
shortParameters = matchValue_1[2];
|
|
506
|
+
shortType = matchValue_1[3];
|
|
507
|
+
shortTypeParameters = matchValue_1[1];
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
matchResult = 1;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
matchResult = 1;
|
|
515
|
+
}
|
|
516
|
+
switch (matchResult) {
|
|
517
|
+
case 0:
|
|
518
|
+
if ((((equalArrays(longKey, shortKey) && equals(longTypeParameters, shortTypeParameters)) && equals(longType, shortType)) && (length(longParameters) > length(shortParameters))) && forAll2((tupledArg, tupledArg_1) => (equals(tupledArg[0], tupledArg_1[0]) && (!tupledArg_1[1] ? true : tupledArg[1])), take(length(shortParameters), longParameters), shortParameters)) {
|
|
519
|
+
return forAll((tuple) => tuple[1], skip(length(shortParameters), longParameters));
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
default:
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
}, members);
|
|
528
|
+
let matchResult_1;
|
|
529
|
+
if (!isEmpty_1(matchValue_3)) {
|
|
530
|
+
if (isEmpty_1(tail(matchValue_3))) {
|
|
531
|
+
matchResult_1 = 0;
|
|
532
|
+
}
|
|
533
|
+
else {
|
|
534
|
+
matchResult_1 = 1;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
else {
|
|
538
|
+
matchResult_1 = 1;
|
|
539
|
+
}
|
|
540
|
+
switch (matchResult_1) {
|
|
541
|
+
case 0:
|
|
542
|
+
return false;
|
|
543
|
+
default:
|
|
544
|
+
return true;
|
|
545
|
+
}
|
|
546
|
+
}, members);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
export function distinctBySignature(aliases, members) {
|
|
550
|
+
const members_2 = withParameterlessOverloads(withoutSubsumedOverloads(aliases, members));
|
|
551
|
+
const methodNames = ofSeq_1(choose((_arg) => {
|
|
520
552
|
if (_arg.tag === 0) {
|
|
521
553
|
return _arg.fields[0].Name;
|
|
522
554
|
}
|
|
523
555
|
else {
|
|
524
556
|
return undefined;
|
|
525
557
|
}
|
|
526
|
-
},
|
|
558
|
+
}, members_2), {
|
|
527
559
|
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
528
560
|
});
|
|
529
561
|
return map((tupledArg) => maxBy((fsharpMember) => {
|
|
@@ -555,17 +587,17 @@ export function distinctBySignature(members) {
|
|
|
555
587
|
switch (_arg_2.tag) {
|
|
556
588
|
case 1: {
|
|
557
589
|
const info_3 = _arg_2.fields[0];
|
|
558
|
-
return new FSharpChoice$3(/* Choice2Of3 */ 1, [[info_3.Name, map((
|
|
590
|
+
return new FSharpChoice$3(/* Choice2Of3 */ 1, [[info_3.Name, map((tuple) => tuple[0], parametersSignature(aliases, info_3.Parameters))]]);
|
|
559
591
|
}
|
|
560
592
|
case 2: {
|
|
561
593
|
const info_4 = _arg_2.fields[0];
|
|
562
|
-
const
|
|
563
|
-
return new FSharpChoice$3(/* Choice3Of3 */ 2, [[info_4.Name,
|
|
594
|
+
const patternInput_1 = signatureKey(aliases, info_4.TypeParameters, info_4.Parameters);
|
|
595
|
+
return new FSharpChoice$3(/* Choice3Of3 */ 2, [[info_4.Name, patternInput_1[0], patternInput_1[1]]]);
|
|
564
596
|
}
|
|
565
597
|
default: {
|
|
566
598
|
const info_2 = _arg_2.fields[0];
|
|
567
|
-
const
|
|
568
|
-
return new FSharpChoice$3(/* Choice1Of3 */ 0, [[info_2.Name,
|
|
599
|
+
const patternInput = signatureKey(aliases, info_2.TypeParameters, info_2.Parameters);
|
|
600
|
+
return new FSharpChoice$3(/* Choice1Of3 */ 0, [[info_2.Name, patternInput[0], patternInput[1]]]);
|
|
569
601
|
}
|
|
570
602
|
}
|
|
571
603
|
}, filter((_arg_1) => {
|
|
@@ -575,15 +607,15 @@ export function distinctBySignature(members) {
|
|
|
575
607
|
else {
|
|
576
608
|
return true;
|
|
577
609
|
}
|
|
578
|
-
},
|
|
610
|
+
}, members_2), {
|
|
579
611
|
Equals: equals,
|
|
580
612
|
GetHashCode: (x_1) => (safeHash(x_1) | 0),
|
|
581
613
|
}));
|
|
582
614
|
}
|
|
583
615
|
|
|
584
|
-
function mergeTypes(types) {
|
|
616
|
+
function mergeTypes(aliases, types) {
|
|
585
617
|
const indexes = new Map([]);
|
|
586
|
-
const
|
|
618
|
+
const seenAliases = new Set([]);
|
|
587
619
|
const result = [];
|
|
588
620
|
const enumerator = getEnumerator(types);
|
|
589
621
|
try {
|
|
@@ -593,7 +625,7 @@ function mergeTypes(types) {
|
|
|
593
625
|
switch (typ.tag) {
|
|
594
626
|
case 9: {
|
|
595
627
|
const aliasInfo = typ.fields[0];
|
|
596
|
-
if (addToSet(`${aliasInfo.Name}/${length(aliasInfo.TypeParameters)}`,
|
|
628
|
+
if (addToSet(`${aliasInfo.Name}/${length(aliasInfo.TypeParameters)}`, seenAliases)) {
|
|
597
629
|
void (result.push(typ));
|
|
598
630
|
}
|
|
599
631
|
break;
|
|
@@ -605,7 +637,7 @@ function mergeTypes(types) {
|
|
|
605
637
|
const existing = item(index, result);
|
|
606
638
|
if (existing.tag === 5) {
|
|
607
639
|
const existingInterfaceInfo = existing.fields[0];
|
|
608
|
-
setItem(result, index, new FSharpType(/* Interface */ 5, [(Members = distinctBySignature(append(existingInterfaceInfo.Members, interfaceInfo.Members)), (Inheritance = List_distinct(append(existingInterfaceInfo.Inheritance, interfaceInfo.Inheritance), {
|
|
640
|
+
setItem(result, index, new FSharpType(/* Interface */ 5, [(Members = distinctBySignature(aliases, append(existingInterfaceInfo.Members, interfaceInfo.Members)), (Inheritance = List_distinct(append(existingInterfaceInfo.Inheritance, interfaceInfo.Inheritance), {
|
|
609
641
|
Equals: equals,
|
|
610
642
|
GetHashCode: (x) => (safeHash(x) | 0),
|
|
611
643
|
}), new FSharpInterface(existingInterfaceInfo.Attributes, existingInterfaceInfo.Name, existingInterfaceInfo.XmlDoc, existingInterfaceInfo.OriginalName, (length(interfaceInfo.TypeParameters) > length(existingInterfaceInfo.TypeParameters)) ? interfaceInfo.TypeParameters : existingInterfaceInfo.TypeParameters, Members, Inheritance)))]));
|
|
@@ -631,7 +663,7 @@ function mergeTypes(types) {
|
|
|
631
663
|
break;
|
|
632
664
|
}
|
|
633
665
|
case 17: {
|
|
634
|
-
if (addToSet(concat("class/", typ.fields[0].Name),
|
|
666
|
+
if (addToSet(concat("class/", typ.fields[0].Name), seenAliases)) {
|
|
635
667
|
void (result.push(typ));
|
|
636
668
|
}
|
|
637
669
|
break;
|
|
@@ -644,10 +676,10 @@ function mergeTypes(types) {
|
|
|
644
676
|
finally {
|
|
645
677
|
disposeSafe(enumerator);
|
|
646
678
|
}
|
|
647
|
-
return
|
|
679
|
+
return ofSeq_2(result);
|
|
648
680
|
}
|
|
649
681
|
|
|
650
|
-
function mergeModules(types) {
|
|
682
|
+
function mergeModules(aliases, types) {
|
|
651
683
|
const indexes = new Map([]);
|
|
652
684
|
const result = [];
|
|
653
685
|
const enumerator = getEnumerator(types);
|
|
@@ -656,13 +688,13 @@ function mergeModules(types) {
|
|
|
656
688
|
const typ = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
657
689
|
if (typ.tag === 4) {
|
|
658
690
|
const moduleInfo = typ.fields[0];
|
|
659
|
-
const newModuleInfo = new FSharpModule(moduleInfo.Name, moduleInfo.IsRecursive, moduleInfo.ImportSpecifier, mergeModules(mergeTypes(moduleInfo.Types)));
|
|
691
|
+
const newModuleInfo = new FSharpModule(moduleInfo.Name, moduleInfo.IsRecursive, moduleInfo.ImportSpecifier, mergeModules(aliases, mergeTypes(aliases, moduleInfo.Types)));
|
|
660
692
|
if (indexes.has(moduleInfo.Name)) {
|
|
661
693
|
const index = getItemFromDict(indexes, moduleInfo.Name) | 0;
|
|
662
694
|
const existing = item(index, result);
|
|
663
695
|
if (existing.tag === 4) {
|
|
664
696
|
const existingModuleInfo = existing.fields[0];
|
|
665
|
-
setItem(result, index, new FSharpType(/* Module */ 4, [new FSharpModule(existingModuleInfo.Name, existingModuleInfo.IsRecursive, existingModuleInfo.ImportSpecifier, mergeModules(mergeTypes(append(existingModuleInfo.Types, newModuleInfo.Types))))]));
|
|
697
|
+
setItem(result, index, new FSharpType(/* Module */ 4, [new FSharpModule(existingModuleInfo.Name, existingModuleInfo.IsRecursive, existingModuleInfo.ImportSpecifier, mergeModules(aliases, mergeTypes(aliases, append(existingModuleInfo.Types, newModuleInfo.Types))))]));
|
|
666
698
|
}
|
|
667
699
|
else {
|
|
668
700
|
throw new Exception("Invalid state");
|
|
@@ -681,7 +713,7 @@ function mergeModules(types) {
|
|
|
681
713
|
finally {
|
|
682
714
|
disposeSafe(enumerator);
|
|
683
715
|
}
|
|
684
|
-
return
|
|
716
|
+
return ofSeq_2(result);
|
|
685
717
|
}
|
|
686
718
|
|
|
687
719
|
function dropEmptyModules(types) {
|
|
@@ -705,23 +737,23 @@ function dropEmptyModules(types) {
|
|
|
705
737
|
}, types);
|
|
706
738
|
}
|
|
707
739
|
|
|
708
|
-
function distinctMembers(types) {
|
|
740
|
+
function distinctMembers(aliases, types) {
|
|
709
741
|
return map((typ) => {
|
|
710
742
|
switch (typ.tag) {
|
|
711
743
|
case 5: {
|
|
712
744
|
const interfaceInfo = typ.fields[0];
|
|
713
|
-
return new FSharpType(/* Interface */ 5, [new FSharpInterface(interfaceInfo.Attributes, interfaceInfo.Name, interfaceInfo.XmlDoc, interfaceInfo.OriginalName, interfaceInfo.TypeParameters, distinctBySignature(interfaceInfo.Members), interfaceInfo.Inheritance)]);
|
|
745
|
+
return new FSharpType(/* Interface */ 5, [new FSharpInterface(interfaceInfo.Attributes, interfaceInfo.Name, interfaceInfo.XmlDoc, interfaceInfo.OriginalName, interfaceInfo.TypeParameters, distinctBySignature(aliases, interfaceInfo.Members), interfaceInfo.Inheritance)]);
|
|
714
746
|
}
|
|
715
747
|
case 17: {
|
|
716
748
|
const classInfo = typ.fields[0];
|
|
717
|
-
return new FSharpType(/* Class */ 17, [new FSharpClass(classInfo.Attributes, classInfo.XmlDoc, classInfo.Name, classInfo.TypeParameters, classInfo.PrimaryConstructor, List_distinctBy((constructorInfo) => parametersSignature(constructorInfo.Parameters), classInfo.SecondaryConstructors, {
|
|
749
|
+
return new FSharpType(/* Class */ 17, [new FSharpClass(classInfo.Attributes, classInfo.XmlDoc, classInfo.Name, classInfo.TypeParameters, classInfo.PrimaryConstructor, List_distinctBy((constructorInfo) => parametersSignature(aliases, constructorInfo.Parameters), classInfo.SecondaryConstructors, {
|
|
718
750
|
Equals: equals,
|
|
719
751
|
GetHashCode: (x) => (safeHash(x) | 0),
|
|
720
752
|
}), classInfo.ExplicitFields)]);
|
|
721
753
|
}
|
|
722
754
|
case 4: {
|
|
723
755
|
const moduleInfo = typ.fields[0];
|
|
724
|
-
return new FSharpType(/* Module */ 4, [new FSharpModule(moduleInfo.Name, moduleInfo.IsRecursive, moduleInfo.ImportSpecifier, distinctMembers(moduleInfo.Types))]);
|
|
756
|
+
return new FSharpType(/* Module */ 4, [new FSharpModule(moduleInfo.Name, moduleInfo.IsRecursive, moduleInfo.ImportSpecifier, distinctMembers(aliases, moduleInfo.Types))]);
|
|
725
757
|
}
|
|
726
758
|
default:
|
|
727
759
|
return typ;
|
|
@@ -729,10 +761,146 @@ function distinctMembers(types) {
|
|
|
729
761
|
}, types);
|
|
730
762
|
}
|
|
731
763
|
|
|
764
|
+
/**
|
|
765
|
+
* TypeScript resolves a call to the first declaration it matches
|
|
766
|
+
*/
|
|
767
|
+
export function disambiguateOverloads(aliases, types) {
|
|
768
|
+
const requiredKey = (fsharpMember) => {
|
|
769
|
+
const key = (name, isStatic, typeParameters, parameters) => {
|
|
770
|
+
if (isEmpty_1(parameters)) {
|
|
771
|
+
return undefined;
|
|
772
|
+
}
|
|
773
|
+
else {
|
|
774
|
+
return [name, isStatic, typeParameters, parametersSignature(aliases, filter((parameter) => !parameter.IsOptional, parameters))];
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
switch (fsharpMember.tag) {
|
|
778
|
+
case 2: {
|
|
779
|
+
const info_1 = fsharpMember.fields[0];
|
|
780
|
+
return key(info_1.Name, true, info_1.TypeParameters, info_1.Parameters);
|
|
781
|
+
}
|
|
782
|
+
case 1:
|
|
783
|
+
return undefined;
|
|
784
|
+
default: {
|
|
785
|
+
const info = fsharpMember.fields[0];
|
|
786
|
+
return key(info.Name, info.IsStatic, info.TypeParameters, info.Parameters);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
return map((_arg_1) => {
|
|
791
|
+
let taken;
|
|
792
|
+
switch (_arg_1.tag) {
|
|
793
|
+
case 5: {
|
|
794
|
+
const interfaceInfo = _arg_1.fields[0];
|
|
795
|
+
return new FSharpType(/* Interface */ 5, [new FSharpInterface(interfaceInfo.Attributes, interfaceInfo.Name, interfaceInfo.XmlDoc, interfaceInfo.OriginalName, interfaceInfo.TypeParameters, (taken = (new HashSet([], {
|
|
796
|
+
Equals: equalArrays,
|
|
797
|
+
GetHashCode: (x) => (arrayHash(x) | 0),
|
|
798
|
+
})), choose((fsharpMember_2) => {
|
|
799
|
+
const matchValue_1 = requiredKey(fsharpMember_2);
|
|
800
|
+
if (matchValue_1 != null) {
|
|
801
|
+
const free = (candidate_mut, key_2_mut) => {
|
|
802
|
+
free:
|
|
803
|
+
while (true) {
|
|
804
|
+
const candidate = candidate_mut, key_2 = key_2_mut;
|
|
805
|
+
if (!taken.has(key_2)) {
|
|
806
|
+
addToSet(key_2, taken);
|
|
807
|
+
return candidate;
|
|
808
|
+
}
|
|
809
|
+
else {
|
|
810
|
+
let matchValue_2;
|
|
811
|
+
const fsharpMember_1 = candidate;
|
|
812
|
+
const promote = (parameters_2) => {
|
|
813
|
+
const matchValue = tryFindIndex((_arg) => _arg.IsOptional, parameters_2);
|
|
814
|
+
if (matchValue != null) {
|
|
815
|
+
const index = matchValue | 0;
|
|
816
|
+
return mapIndexed((currentIndex, parameter_1) => {
|
|
817
|
+
if (currentIndex === index) {
|
|
818
|
+
return new FSharpParameter(parameter_1.Attributes, parameter_1.Name, false, parameter_1.Type, parameter_1.OriginalGlueMember);
|
|
819
|
+
}
|
|
820
|
+
else {
|
|
821
|
+
return parameter_1;
|
|
822
|
+
}
|
|
823
|
+
}, parameters_2);
|
|
824
|
+
}
|
|
825
|
+
else {
|
|
826
|
+
return undefined;
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
switch (fsharpMember_1.tag) {
|
|
830
|
+
case 2: {
|
|
831
|
+
const info_3 = fsharpMember_1.fields[0];
|
|
832
|
+
const option_3 = promote(info_3.Parameters);
|
|
833
|
+
matchValue_2 = ((option_3 != null) ? (new FSharpMember(/* StaticMember */ 2, [new FSharpStaticMemberInfo(info_3.Attributes, info_3.Name, info_3.OriginalName, info_3.TypeParameters, option_3, info_3.Type, info_3.IsOptional, info_3.Accessor, info_3.Accessibility, info_3.XmlDoc)])) : undefined);
|
|
834
|
+
break;
|
|
835
|
+
}
|
|
836
|
+
case 1: {
|
|
837
|
+
matchValue_2 = fsharpMember_1;
|
|
838
|
+
break;
|
|
839
|
+
}
|
|
840
|
+
default: {
|
|
841
|
+
const info_2 = fsharpMember_1.fields[0];
|
|
842
|
+
const option_1 = promote(info_2.Parameters);
|
|
843
|
+
matchValue_2 = ((option_1 != null) ? (new FSharpMember(/* Method */ 0, [new FSharpMemberInfo(info_2.Attributes, info_2.Name, info_2.OriginalName, info_2.TypeParameters, option_1, info_2.Type, info_2.IsOptional, info_2.IsStatic, info_2.Accessor, info_2.Accessibility, info_2.XmlDoc, info_2.Body)])) : undefined);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
if (matchValue_2 != null) {
|
|
847
|
+
const promoted = matchValue_2;
|
|
848
|
+
const matchValue_3 = requiredKey(promoted);
|
|
849
|
+
if (matchValue_3 != null) {
|
|
850
|
+
candidate_mut = promoted;
|
|
851
|
+
key_2_mut = matchValue_3;
|
|
852
|
+
continue free;
|
|
853
|
+
}
|
|
854
|
+
else {
|
|
855
|
+
return undefined;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
else {
|
|
859
|
+
return undefined;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
break;
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
return free(fsharpMember_2, matchValue_1);
|
|
866
|
+
}
|
|
867
|
+
else {
|
|
868
|
+
return fsharpMember_2;
|
|
869
|
+
}
|
|
870
|
+
}, interfaceInfo.Members)), interfaceInfo.Inheritance)]);
|
|
871
|
+
}
|
|
872
|
+
case 4: {
|
|
873
|
+
const moduleInfo = _arg_1.fields[0];
|
|
874
|
+
return new FSharpType(/* Module */ 4, [new FSharpModule(moduleInfo.Name, moduleInfo.IsRecursive, moduleInfo.ImportSpecifier, disambiguateOverloads(aliases, moduleInfo.Types))]);
|
|
875
|
+
}
|
|
876
|
+
default:
|
|
877
|
+
return _arg_1;
|
|
878
|
+
}
|
|
879
|
+
}, types);
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* If a type is declared twice, merge them into one.
|
|
884
|
+
*
|
|
885
|
+
* This can happens because TypeScript allows multiple declarations of the same type.
|
|
886
|
+
*
|
|
887
|
+
* Example:
|
|
888
|
+
*
|
|
889
|
+
* <code lang="typescript">
|
|
890
|
+
* interface A {
|
|
891
|
+
* a: string;
|
|
892
|
+
* }
|
|
893
|
+
*
|
|
894
|
+
* interface A {
|
|
895
|
+
* b: number;
|
|
896
|
+
* }
|
|
897
|
+
* </code>
|
|
898
|
+
*/
|
|
899
|
+
export function applyWith(aliases, types) {
|
|
900
|
+
return distinctMembers(aliases, dropEmptyModules(mergeModules(aliases, mergeTypes(aliases, types))));
|
|
901
|
+
}
|
|
902
|
+
|
|
732
903
|
export function apply(types) {
|
|
733
|
-
|
|
734
|
-
genericAliasTargets.clear();
|
|
735
|
-
collectAliases(empty(), types);
|
|
736
|
-
return distinctMembers(dropEmptyModules(mergeModules(mergeTypes(types))));
|
|
904
|
+
return applyWith(aliasesOf(types), types);
|
|
737
905
|
}
|
|
738
906
|
|