@glutinum/cli 1.0.0-beta.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 +116 -65
- package/dist/Glutinum.Converter/Generate.js +38 -25
- package/dist/Glutinum.Converter/GlueAST.js +82 -43
- package/dist/Glutinum.Converter/Hosting.js +143 -169
- package/dist/Glutinum.Converter/Merge.js +369 -337
- package/dist/Glutinum.Converter/Packages.js +384 -94
- package/dist/Glutinum.Converter/Printer.js +432 -393
- package/dist/Glutinum.Converter/Read.js +361 -99
- package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +4 -4
- package/dist/Glutinum.Converter/Reader/ConditionalTypeNode.js +90 -0
- package/dist/Glutinum.Converter/Reader/Declaration.js +6 -12
- package/dist/Glutinum.Converter/Reader/Deferred.js +706 -0
- package/dist/Glutinum.Converter/Reader/Documentation.js +23 -35
- package/dist/Glutinum.Converter/Reader/ExportAssignment.js +103 -36
- package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +21 -36
- package/dist/Glutinum.Converter/Reader/ExpressionWithTypeArguments.js +59 -0
- package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +26 -13
- package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +15 -21
- package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +45 -2
- package/dist/Glutinum.Converter/Reader/IntersectionTypeNode.js +178 -0
- package/dist/Glutinum.Converter/Reader/MemberTypes.js +126 -0
- package/dist/Glutinum.Converter/Reader/ModuleDeclaration.js +53 -5
- package/dist/Glutinum.Converter/Reader/Node.js +8 -11
- package/dist/Glutinum.Converter/Reader/Parameters.js +36 -27
- package/dist/Glutinum.Converter/Reader/TypeNode.js +389 -1583
- package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +76 -49
- package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +14 -37
- package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +23 -5
- package/dist/Glutinum.Converter/Reader/Types.js +295 -15
- package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +14 -28
- package/dist/Glutinum.Converter/Reader/UtilityType.js +811 -0
- package/dist/Glutinum.Converter/Reader/Utils.js +487 -101
- package/dist/Glutinum.Converter/Reader/VariableStatement.js +2 -3
- package/dist/Glutinum.Converter/Transform.js +2915 -8176
- 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 +0 -10
- package/dist/Glutinum.Converter/Utils/String.js +14 -3
- package/dist/Program.js +102 -239
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -64,6 +64,8 @@ The bindings of the runtimes are generated from this repository and published on
|
|
|
64
64
|
|
|
65
65
|
A binding generated for a package using the DOM or the Node types references them instead of generating them again, the header of the file tells which one to add. `--no-externals` generates them inline.
|
|
66
66
|
|
|
67
|
+
A single `.d.ts` declaring the globals of a script, the hooks of PocketBase for example, is generated with `--global`: its functions and variables are globals instead of imports. A parameter typed by a union gives one overload per case; `--max-overloads <count>` caps the overloads a signature gets this way, 16 by default, the parameters past the cap keep their erased union.
|
|
68
|
+
|
|
67
69
|
`./build.sh bindings` regenerates them from the versions pinned in `bindings/package.json`, `./build.sh test bindings` runs them in Node and Chromium.
|
|
68
70
|
|
|
69
71
|
## Contributing
|
|
@@ -119,6 +121,20 @@ From a macro view, it does the following:
|
|
|
119
121
|
2. Transform the GlueAST to FsharpAST
|
|
120
122
|
3. Print the F# code from FsharpAST
|
|
121
123
|
|
|
124
|
+
#### Layout
|
|
125
|
+
|
|
126
|
+
| Path | Content |
|
|
127
|
+
| --- | --- |
|
|
128
|
+
| `Reader/` | One reader per TypeScript node kind. `Reader/Types.fs` declares `ITypeScriptReader`, the interface the readers call each other through, and `Reader/TypeScriptReader.fs` implements it. `Read.fs` reads a file or the files of the packages. |
|
|
129
|
+
| `GlueAST.fs`, `FsharpAST.fs` | The two ASTs. `FSharpType.mapChildren` and `FSharpType.children` walk the child types of an F# type, every traversal of the F# AST builds on them. |
|
|
130
|
+
| `Transformer/` | The parts of the transform which do not call `transformType`: the comment transform, the type parameter and heritage helpers, the analyses of the type memory (`ParamObjectCandidate`, `Conditionals`, `KeyOfMaps`, `UnionOverloads`, `AnyFunctionOverloads`, `CallableProperties`), the enum transform, and `Context.fs` with `TransformContext`, the scope every transform function receives. |
|
|
131
|
+
| `Transform.fs` | The recursive core: `transformType`, the members, the exports, the declarations. The entry point is `Transform.applyWith`. |
|
|
132
|
+
| `Merge.fs`, `Abbreviations.fs`, `FreeTypeParameters.fs`, `DelegateExtensions.fs` | The passes over the F# AST run after the transform, in this order. |
|
|
133
|
+
| `Printer.fs` | The F# AST to text. |
|
|
134
|
+
| `Hosting.fs`, `Packages.fs`, `Generate.fs` | Package resolution, the program creation, and the entry points of the CLI and of the web app. |
|
|
135
|
+
|
|
136
|
+
The state of a run is explicit. The reader keeps the declarations it is reading in `ITypeScriptReader.InProgress`. The transform builds a `TransformState` from the type memory once, in `Transform.applyWith`, and reaches it as `context.State`. `Merge.Aliases` is computed from the transform output and given to the passes needing it. No module holds a mutable value between two runs.
|
|
137
|
+
|
|
122
138
|
#### GlueAST
|
|
123
139
|
|
|
124
140
|
GlueAST philosophy is to follow the TypeScript AST naming convention as much as possible. Its goal is to provide an easier to use AST than the TypeScript one thanks to F# type system (mainly thanks to discriminated unions).
|
|
@@ -5,7 +5,7 @@ import { defaultOf, equals, disposeSafe, getEnumerator, int32ToString } from "..
|
|
|
5
5
|
import { tryGetValue, getItemFromDict, addToSet } from "../fable_modules/fable-library-js.5.17.2/MapUtil.js";
|
|
6
6
|
import { empty, singleton as singleton_1, append as append_1, map, delay, toList } from "../fable_modules/fable-library-js.5.17.2/Seq.js";
|
|
7
7
|
import { rangeDouble } from "../fable_modules/fable-library-js.5.17.2/Range.js";
|
|
8
|
-
import { FSharpModule, FSharpTypeAlias,
|
|
8
|
+
import { FSharpModule, FSharpTypeAlias, FSharpTypeModule_mapChildren, FSharpMapped, FSharpTypeParameter, FSharpTypeReference, FSharpType } from "./FsharpAST.js";
|
|
9
9
|
import { FSharpRef } from "../fable_modules/fable-library-js.5.17.2/Types.js";
|
|
10
10
|
|
|
11
11
|
function key(path, name, arity) {
|
|
@@ -172,31 +172,8 @@ export function apply(types) {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
-
case 1: {
|
|
176
|
-
const unionInfo = typ.fields[0];
|
|
177
|
-
return new FSharpType(/* Union */ 1, [new FSharpUnion(unionInfo.Attributes, unionInfo.Name, map_1((_arg_1) => {
|
|
178
|
-
switch (_arg_1.tag) {
|
|
179
|
-
case 1:
|
|
180
|
-
return new FSharpUnionCase(/* Typed */ 1, [cut(_arg_1.fields[0])]);
|
|
181
|
-
case 2:
|
|
182
|
-
return new FSharpUnionCase(/* Field */ 2, [_arg_1.fields[0], cut(_arg_1.fields[1])]);
|
|
183
|
-
default:
|
|
184
|
-
return _arg_1;
|
|
185
|
-
}
|
|
186
|
-
}, unionInfo.Cases), unionInfo.IsOptional, unionInfo.TypeParameters, unionInfo.Constants)]);
|
|
187
|
-
}
|
|
188
|
-
case 3:
|
|
189
|
-
return new FSharpType(/* Option */ 3, [cut(typ.fields[0])]);
|
|
190
|
-
case 14:
|
|
191
|
-
return new FSharpType(/* ResizeArray */ 14, [cut(typ.fields[0])]);
|
|
192
|
-
case 12:
|
|
193
|
-
return new FSharpType(/* Tuple */ 12, [map_1(cut, typ.fields[0])]);
|
|
194
|
-
case 16: {
|
|
195
|
-
const functionInfo = typ.fields[0];
|
|
196
|
-
return new FSharpType(/* Function */ 16, [new FSharpFunctionType(map_1((parameter) => (new FSharpParameter(parameter.Attributes, parameter.Name, parameter.IsOptional, cut(parameter.Type), parameter.OriginalGlueMember)), functionInfo.Parameters), cut(functionInfo.ReturnType))]);
|
|
197
|
-
}
|
|
198
175
|
default:
|
|
199
|
-
return typ;
|
|
176
|
+
return FSharpTypeModule_mapChildren(cut, typ);
|
|
200
177
|
}
|
|
201
178
|
};
|
|
202
179
|
const cutType = cut(aliasInfo.Type);
|
|
@@ -216,10 +193,10 @@ export function apply(types) {
|
|
|
216
193
|
return types;
|
|
217
194
|
}
|
|
218
195
|
else {
|
|
219
|
-
const rewrite = (path_1,
|
|
220
|
-
switch (
|
|
196
|
+
const rewrite = (path_1, types_1) => map_1((typ_3) => {
|
|
197
|
+
switch (typ_3.tag) {
|
|
221
198
|
case 9: {
|
|
222
|
-
const aliasInfo_2 =
|
|
199
|
+
const aliasInfo_2 = typ_3.fields[0];
|
|
223
200
|
let matchValue_2;
|
|
224
201
|
let outArg = defaultOf();
|
|
225
202
|
matchValue_2 = [tryGetValue(rewritten, key(path_1, aliasInfo_2.Name, length(aliasInfo_2.TypeParameters)), new FSharpRef(() => outArg, (v) => {
|
|
@@ -229,17 +206,17 @@ export function apply(types) {
|
|
|
229
206
|
return new FSharpType(/* TypeAlias */ 9, [matchValue_2[1]]);
|
|
230
207
|
}
|
|
231
208
|
else {
|
|
232
|
-
return
|
|
209
|
+
return typ_3;
|
|
233
210
|
}
|
|
234
211
|
}
|
|
235
212
|
case 4: {
|
|
236
|
-
const moduleInfo =
|
|
213
|
+
const moduleInfo = typ_3.fields[0];
|
|
237
214
|
return new FSharpType(/* Module */ 4, [new FSharpModule(moduleInfo.Name, moduleInfo.IsRecursive, moduleInfo.ImportSpecifier, rewrite(append(path_1, singleton(moduleInfo.Name)), moduleInfo.Types))]);
|
|
238
215
|
}
|
|
239
216
|
default:
|
|
240
|
-
return
|
|
217
|
+
return typ_3;
|
|
241
218
|
}
|
|
242
|
-
},
|
|
219
|
+
}, types_1);
|
|
243
220
|
return rewrite(empty_1(), types);
|
|
244
221
|
}
|
|
245
222
|
}
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
|
|
2
|
+
import { comparePrimitives, defaultOf, safeHash, equals, disposeSafe, getEnumerator } from "../fable_modules/fable-library-js.5.17.2/Util.js";
|
|
3
|
+
import { split, join } from "../fable_modules/fable-library-js.5.17.2/String.js";
|
|
4
|
+
import { choose, take, ofArray, map, isEmpty, contains, forAll, empty, cons, collect, singleton, append } from "../fable_modules/fable-library-js.5.17.2/List.js";
|
|
5
|
+
import { FSharpModule, FSharpTypeExtension, FSharpDelegateExtension, FSharpParameter, FSharpTypeModule_mapChildren, FSharpMapped, FSharpTypeParameter, FSharpType, FSharpTypeReference, FSharpAttribute, FSharpTypeModule_children } from "./FsharpAST.js";
|
|
6
|
+
import { item } from "../fable_modules/fable-library-js.5.17.2/Array.js";
|
|
7
|
+
import { tryGetValue } from "../fable_modules/fable-library-js.5.17.2/MapUtil.js";
|
|
8
|
+
import { FSharpRef } from "../fable_modules/fable-library-js.5.17.2/Types.js";
|
|
9
|
+
import { FSharpSet__Contains, ofList } from "../fable_modules/fable-library-js.5.17.2/Set.js";
|
|
10
|
+
|
|
11
|
+
function collectDelegates(path, types, into) {
|
|
12
|
+
const enumerator = getEnumerator(types);
|
|
13
|
+
try {
|
|
14
|
+
while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
|
|
15
|
+
const typ = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
16
|
+
switch (typ.tag) {
|
|
17
|
+
case 20: {
|
|
18
|
+
const info = typ.fields[0];
|
|
19
|
+
into.set(join(".", append(path, singleton(info.Name))), info);
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
case 4: {
|
|
23
|
+
const moduleInfo = typ.fields[0];
|
|
24
|
+
collectDelegates(append(path, singleton(moduleInfo.Name)), moduleInfo.Types, into);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
default:
|
|
28
|
+
undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
disposeSafe(enumerator);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function namesIn(typ) {
|
|
38
|
+
switch (typ.tag) {
|
|
39
|
+
case 9: {
|
|
40
|
+
const info = typ.fields[0];
|
|
41
|
+
return cons(info.Name, collect(namesInParameter, info.TypeParameters));
|
|
42
|
+
}
|
|
43
|
+
case 7: {
|
|
44
|
+
const info_1 = typ.fields[0];
|
|
45
|
+
return cons(info_1.Name, collect(namesInParameter, info_1.TypeParameters));
|
|
46
|
+
}
|
|
47
|
+
case 11: {
|
|
48
|
+
const info_2 = typ.fields[0];
|
|
49
|
+
return cons(join(".", append(info_2.ModulePath, singleton(info_2.Name))), collect(namesIn, info_2.TypeArguments));
|
|
50
|
+
}
|
|
51
|
+
default:
|
|
52
|
+
return collect(namesIn, FSharpTypeModule_children(typ));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function namesInParameter(typeParameter) {
|
|
57
|
+
if (typeParameter.tag === 1) {
|
|
58
|
+
return empty();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return namesIn(typeParameter.fields[0]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function isPlain(delegateInfo) {
|
|
66
|
+
const nestedPrefix = delegateInfo.Name + ".";
|
|
67
|
+
const parametersAreRequired = forAll((parameter) => {
|
|
68
|
+
if (!parameter.IsOptional) {
|
|
69
|
+
return !contains(FSharpAttribute.ParamArray, parameter.Attributes, {
|
|
70
|
+
Equals: equals,
|
|
71
|
+
GetHashCode: (x) => (safeHash(x) | 0),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}, delegateInfo.Parameters);
|
|
78
|
+
const mentionsNoNestedType = forAll((name) => !(name.startsWith(nestedPrefix) ? true : (name.indexOf("." + nestedPrefix) >= 0)), append(namesIn(delegateInfo.ReturnType), collect((parameter_1) => namesIn(parameter_1.Type), delegateInfo.Parameters)));
|
|
79
|
+
if (isEmpty(delegateInfo.TypeParameters) && parametersAreRequired) {
|
|
80
|
+
return mentionsNoNestedType;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function qualify(modulePath, declared, typ) {
|
|
88
|
+
let info;
|
|
89
|
+
const qualify_1 = (typ_1) => qualify(modulePath, declared, typ_1);
|
|
90
|
+
const isDeclared = (name) => declared.has(item(0, split(name, ["."], undefined, 0)));
|
|
91
|
+
let matchResult, info_2, info_3, typ_3;
|
|
92
|
+
switch (typ.tag) {
|
|
93
|
+
case 11: {
|
|
94
|
+
if ((info = typ.fields[0], isEmpty(info.ModulePath) && isDeclared(info.Name))) {
|
|
95
|
+
matchResult = 0;
|
|
96
|
+
info_2 = typ.fields[0];
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
matchResult = 2;
|
|
100
|
+
typ_3 = typ;
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
case 7: {
|
|
105
|
+
if (isDeclared(typ.fields[0].Name)) {
|
|
106
|
+
matchResult = 1;
|
|
107
|
+
info_3 = typ.fields[0];
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
matchResult = 2;
|
|
111
|
+
typ_3 = typ;
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
default: {
|
|
116
|
+
matchResult = 2;
|
|
117
|
+
typ_3 = typ;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
switch (matchResult) {
|
|
121
|
+
case 0:
|
|
122
|
+
return new FSharpType(/* TypeReference */ 11, [new FSharpTypeReference(info_2.Name, info_2.FullName, modulePath, map(qualify_1, info_2.TypeArguments), info_2.Type)]);
|
|
123
|
+
case 1:
|
|
124
|
+
return new FSharpType(/* Mapped */ 7, [new FSharpMapped(join(".", append(modulePath, singleton(info_3.Name))), map((_arg) => {
|
|
125
|
+
if (_arg.tag === 0) {
|
|
126
|
+
return new FSharpTypeParameter(/* FSharpType */ 0, [qualify_1(_arg.fields[0])]);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
return _arg;
|
|
130
|
+
}
|
|
131
|
+
}, info_3.TypeParameters))]);
|
|
132
|
+
default:
|
|
133
|
+
return FSharpTypeModule_mapChildren(qualify_1, typ_3);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function extensionOf(delegates, declaredIn, path, fsharpMember) {
|
|
138
|
+
let matchResult, info_1;
|
|
139
|
+
if (fsharpMember.tag === 1) {
|
|
140
|
+
if (isEmpty(fsharpMember.fields[0].Parameters)) {
|
|
141
|
+
if (fsharpMember.fields[0].IsOptional) {
|
|
142
|
+
matchResult = 1;
|
|
143
|
+
}
|
|
144
|
+
else if (fsharpMember.fields[0].IsStatic) {
|
|
145
|
+
matchResult = 1;
|
|
146
|
+
}
|
|
147
|
+
else if (!(fsharpMember.fields[0].Type.tag === 3)) {
|
|
148
|
+
matchResult = 0;
|
|
149
|
+
info_1 = fsharpMember.fields[0];
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
matchResult = 1;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
matchResult = 1;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
matchResult = 1;
|
|
161
|
+
}
|
|
162
|
+
switch (matchResult) {
|
|
163
|
+
case 0: {
|
|
164
|
+
let delegateInfo;
|
|
165
|
+
let option_1;
|
|
166
|
+
const typ = info_1.Type;
|
|
167
|
+
let matchResult_1, name, name_1, modulePath, name_2;
|
|
168
|
+
switch (typ.tag) {
|
|
169
|
+
case 9: {
|
|
170
|
+
if (typ.fields[0].Type.tag === 10) {
|
|
171
|
+
if (isEmpty(typ.fields[0].TypeParameters)) {
|
|
172
|
+
matchResult_1 = 0;
|
|
173
|
+
name = typ.fields[0].Name;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
matchResult_1 = 3;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
matchResult_1 = 3;
|
|
181
|
+
}
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case 7: {
|
|
185
|
+
if (isEmpty(typ.fields[0].TypeParameters)) {
|
|
186
|
+
matchResult_1 = 1;
|
|
187
|
+
name_1 = typ.fields[0].Name;
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
matchResult_1 = 3;
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
case 11: {
|
|
195
|
+
if (isEmpty(typ.fields[0].TypeArguments)) {
|
|
196
|
+
matchResult_1 = 2;
|
|
197
|
+
modulePath = typ.fields[0].ModulePath;
|
|
198
|
+
name_2 = typ.fields[0].Name;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
matchResult_1 = 3;
|
|
202
|
+
}
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
default:
|
|
206
|
+
matchResult_1 = 3;
|
|
207
|
+
}
|
|
208
|
+
switch (matchResult_1) {
|
|
209
|
+
case 0: {
|
|
210
|
+
option_1 = name;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case 1: {
|
|
214
|
+
option_1 = name_1;
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
case 2: {
|
|
218
|
+
option_1 = join(".", append(modulePath, singleton(name_2)));
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
default:
|
|
222
|
+
option_1 = undefined;
|
|
223
|
+
}
|
|
224
|
+
if (option_1 != null) {
|
|
225
|
+
const key = option_1;
|
|
226
|
+
let matchValue;
|
|
227
|
+
let outArg = defaultOf();
|
|
228
|
+
matchValue = [tryGetValue(delegates, key, new FSharpRef(() => outArg, (v) => {
|
|
229
|
+
outArg = v;
|
|
230
|
+
})), outArg];
|
|
231
|
+
delegateInfo = (matchValue[0] ? [key, matchValue[1]] : undefined);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
delegateInfo = undefined;
|
|
235
|
+
}
|
|
236
|
+
let matchResult_2, delegateInfo_2, key_2;
|
|
237
|
+
if (delegateInfo != null) {
|
|
238
|
+
if ((delegateInfo[0], isPlain(delegateInfo[1]))) {
|
|
239
|
+
matchResult_2 = 0;
|
|
240
|
+
delegateInfo_2 = delegateInfo[1];
|
|
241
|
+
key_2 = delegateInfo[0];
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
matchResult_2 = 1;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
matchResult_2 = 1;
|
|
249
|
+
}
|
|
250
|
+
switch (matchResult_2) {
|
|
251
|
+
case 0: {
|
|
252
|
+
let delegatePath;
|
|
253
|
+
const list = ofArray(split(key_2, ["."], undefined, 0));
|
|
254
|
+
delegatePath = take(split(key_2, ["."], undefined, 0).length - 1, list);
|
|
255
|
+
const qualify_1 = (typ_2) => {
|
|
256
|
+
let matchValue_1;
|
|
257
|
+
let outArg_1 = defaultOf();
|
|
258
|
+
matchValue_1 = [tryGetValue(declaredIn, join(".", delegatePath), new FSharpRef(() => outArg_1, (v_1) => {
|
|
259
|
+
outArg_1 = v_1;
|
|
260
|
+
})), outArg_1];
|
|
261
|
+
let matchResult_3;
|
|
262
|
+
if (matchValue_1[0]) {
|
|
263
|
+
if (!equals(delegatePath, path) && !isEmpty(delegatePath)) {
|
|
264
|
+
matchResult_3 = 0;
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
matchResult_3 = 1;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
matchResult_3 = 1;
|
|
272
|
+
}
|
|
273
|
+
switch (matchResult_3) {
|
|
274
|
+
case 0:
|
|
275
|
+
return qualify(delegatePath, matchValue_1[1], typ_2);
|
|
276
|
+
default:
|
|
277
|
+
return typ_2;
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
return new FSharpDelegateExtension(info_1.Name, map((parameter) => (new FSharpParameter(parameter.Attributes, parameter.Name, parameter.IsOptional, qualify_1(parameter.Type), parameter.OriginalGlueMember)), delegateInfo_2.Parameters), qualify_1(delegateInfo_2.ReturnType));
|
|
281
|
+
}
|
|
282
|
+
default:
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
default:
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function declaredNames(types) {
|
|
292
|
+
return ofList(choose((_arg) => {
|
|
293
|
+
switch (_arg.tag) {
|
|
294
|
+
case 5:
|
|
295
|
+
return _arg.fields[0].Name;
|
|
296
|
+
case 17:
|
|
297
|
+
return _arg.fields[0].Name;
|
|
298
|
+
case 1:
|
|
299
|
+
return _arg.fields[0].Name;
|
|
300
|
+
case 0:
|
|
301
|
+
return _arg.fields[0].Name;
|
|
302
|
+
case 9:
|
|
303
|
+
return _arg.fields[0].Name;
|
|
304
|
+
case 20:
|
|
305
|
+
return _arg.fields[0].Name;
|
|
306
|
+
case 4:
|
|
307
|
+
return _arg.fields[0].Name;
|
|
308
|
+
default:
|
|
309
|
+
return undefined;
|
|
310
|
+
}
|
|
311
|
+
}, types), {
|
|
312
|
+
Compare: (x, y) => (comparePrimitives(x, y) | 0),
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function collectDeclared(path, types, into) {
|
|
317
|
+
into.set(join(".", path), new Set(declaredNames(types)));
|
|
318
|
+
const enumerator = getEnumerator(types);
|
|
319
|
+
try {
|
|
320
|
+
while (enumerator["System.Collections.IEnumerator.MoveNext"]()) {
|
|
321
|
+
const typ = enumerator["System.Collections.Generic.IEnumerator`1.get_Current"]();
|
|
322
|
+
if (typ.tag === 4) {
|
|
323
|
+
const moduleInfo = typ.fields[0];
|
|
324
|
+
collectDeclared(append(path, singleton(moduleInfo.Name)), moduleInfo.Types, into);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
finally {
|
|
329
|
+
disposeSafe(enumerator);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function extend(delegates, declaredIn, path, types) {
|
|
334
|
+
const taken = declaredNames(types);
|
|
335
|
+
return collect((typ) => {
|
|
336
|
+
switch (typ.tag) {
|
|
337
|
+
case 5: {
|
|
338
|
+
const interfaceInfo = typ.fields[0];
|
|
339
|
+
const matchValue = choose((fsharpMember) => extensionOf(delegates, declaredIn, path, fsharpMember), interfaceInfo.Members);
|
|
340
|
+
if (isEmpty(matchValue)) {
|
|
341
|
+
return singleton(typ);
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
const free = (name_mut) => {
|
|
345
|
+
free:
|
|
346
|
+
while (true) {
|
|
347
|
+
const name = name_mut;
|
|
348
|
+
if (FSharpSet__Contains(taken, name)) {
|
|
349
|
+
name_mut = (name + "_");
|
|
350
|
+
continue free;
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
return name;
|
|
354
|
+
}
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
return ofArray([typ, new FSharpType(/* TypeExtension */ 21, [new FSharpTypeExtension(free(interfaceInfo.Name + "Extensions"), interfaceInfo.Name, interfaceInfo.TypeParameters, matchValue)])]);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
case 4: {
|
|
362
|
+
const moduleInfo = typ.fields[0];
|
|
363
|
+
return singleton(new FSharpType(/* Module */ 4, [new FSharpModule(moduleInfo.Name, moduleInfo.IsRecursive, moduleInfo.ImportSpecifier, extend(delegates, declaredIn, append(path, singleton(moduleInfo.Name)), moduleInfo.Types))]));
|
|
364
|
+
}
|
|
365
|
+
default:
|
|
366
|
+
return singleton(typ);
|
|
367
|
+
}
|
|
368
|
+
}, types);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export function apply(types) {
|
|
372
|
+
const delegates = new Map([]);
|
|
373
|
+
collectDelegates(empty(), types, delegates);
|
|
374
|
+
const declaredIn = new Map([]);
|
|
375
|
+
collectDeclared(empty(), types, declaredIn);
|
|
376
|
+
return extend(delegates, declaredIn, empty(), types);
|
|
377
|
+
}
|
|
378
|
+
|