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

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.
@@ -1,7 +1,7 @@
1
1
 
2
2
  import { ofList as ofList_1, empty as empty_1, FSharpSet__Add, FSharpSet__Contains, ofSeq } from "../../fable_modules/fable-library-js.5.17.2/Set.js";
3
3
  import { equals, comparePrimitives } from "../../fable_modules/fable-library-js.5.17.2/Util.js";
4
- import { fold, exists, take, forAll2, length, head, tail, isEmpty, map, singleton, filter, empty, choose, append, collect, tryPick } from "../../fable_modules/fable-library-js.5.17.2/List.js";
4
+ import { exists, take, forAll2, length, forAll, indexed as indexed_1, fold, head, tail, isEmpty, map, singleton, filter, empty, choose, append, collect, tryPick } from "../../fable_modules/fable-library-js.5.17.2/List.js";
5
5
  import { defaultArg } from "../../fable_modules/fable-library-js.5.17.2/Option.js";
6
6
  import { Record } from "../../fable_modules/fable-library-js.5.17.2/Types.js";
7
7
  import { GlueSubstitution_substitute, GlueSubstitution_substituteMember, GlueSubstitution_ofTypeArguments, GlueSubstitution_substituteParameter, GluePrimitive, GlueTypeReference, GlueTypeUnion, GlueType, GlueFunctionType, GlueParameter, GlueType_$reflection, GlueMember_$reflection, GlueTypeParameter_$reflection } from "../GlueAST.js";
@@ -20,7 +20,7 @@ export function isInheritableType(typ) {
20
20
  return false;
21
21
  case 11: {
22
22
  const typeReference = typ.fields[0];
23
- if (!typeReference.Name.startsWith("JS.") && (typeReference.Name !== "Action")) {
23
+ if ((!typeReference.Name.startsWith("JS.") && (typeReference.Name !== "Action")) && (typeReference.Name !== "RegExp")) {
24
24
  return !FSharpSet__Contains(primitiveNames, typeReference.Name);
25
25
  }
26
26
  else {
@@ -210,6 +210,93 @@ function tryFindBase(typeMemory, typeReference) {
210
210
  }
211
211
  }
212
212
 
213
+ /**
214
+ * F# rejects an interface inherited twice with different type arguments (FS3360)
215
+ */
216
+ export function withoutBasesOfBases(typeMemory, heritageClauses) {
217
+ const basesBelow = (visited, clause) => {
218
+ let typeReference;
219
+ let matchResult, typeReference_1;
220
+ if (clause.tag === 13) {
221
+ if ((typeReference = clause.fields[0], (typeReference.FullName !== "") && !FSharpSet__Contains(visited, typeReference.FullName))) {
222
+ matchResult = 0;
223
+ typeReference_1 = clause.fields[0];
224
+ }
225
+ else {
226
+ matchResult = 1;
227
+ }
228
+ }
229
+ else {
230
+ matchResult = 1;
231
+ }
232
+ switch (matchResult) {
233
+ case 0: {
234
+ const matchValue = tryFindBase(typeMemory, typeReference_1);
235
+ if (matchValue == null) {
236
+ return visited;
237
+ }
238
+ else {
239
+ return fold((acc, baseClause) => {
240
+ let matchResult_1, baseReference_1;
241
+ if (baseClause.tag === 13) {
242
+ if (baseClause.fields[0].FullName !== "") {
243
+ matchResult_1 = 0;
244
+ baseReference_1 = baseClause.fields[0];
245
+ }
246
+ else {
247
+ matchResult_1 = 1;
248
+ }
249
+ }
250
+ else {
251
+ matchResult_1 = 1;
252
+ }
253
+ switch (matchResult_1) {
254
+ case 0:
255
+ return basesBelow(FSharpSet__Add(acc, baseReference_1.FullName), baseClause);
256
+ default:
257
+ return acc;
258
+ }
259
+ }, visited, matchValue.HeritageClauses);
260
+ }
261
+ }
262
+ default:
263
+ return visited;
264
+ }
265
+ };
266
+ const indexed = indexed_1(heritageClauses);
267
+ return map((tuple) => tuple[1], filter((tupledArg) => {
268
+ const clause_1 = tupledArg[1];
269
+ let matchResult_2, typeReference_3;
270
+ if (clause_1.tag === 13) {
271
+ if (clause_1.fields[0].FullName !== "") {
272
+ matchResult_2 = 0;
273
+ typeReference_3 = clause_1.fields[0];
274
+ }
275
+ else {
276
+ matchResult_2 = 1;
277
+ }
278
+ }
279
+ else {
280
+ matchResult_2 = 1;
281
+ }
282
+ switch (matchResult_2) {
283
+ case 0:
284
+ return forAll((tupledArg_1) => {
285
+ if (tupledArg_1[0] === tupledArg[0]) {
286
+ return true;
287
+ }
288
+ else {
289
+ return !FSharpSet__Contains(basesBelow(empty_1({
290
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
291
+ }), tupledArg_1[1]), typeReference_3.FullName);
292
+ }
293
+ }, indexed);
294
+ default:
295
+ return true;
296
+ }
297
+ }, indexed));
298
+ }
299
+
213
300
  function memberName(glueMember) {
214
301
  switch (glueMember.tag) {
215
302
  case 6:
@@ -0,0 +1,219 @@
1
+
2
+ import { Record } from "../../fable_modules/fable-library-js.5.17.2/Types.js";
3
+ import { list_type, option_type, record_type, string_type } from "../../fable_modules/fable-library-js.5.17.2/Reflection.js";
4
+ import { FSharpParameter, FSharpTypeAlias, FSharpFunctionType, FSharpUnion, FSharpUnionCase, FSharpTypeReference, FSharpType, FSharpMapped, FSharpTypeParameter, FSharpTypeParameterInfo_Create_Z6CFD3565, FSharpTypeParameter_$reflection, FSharpType_$reflection } from "../FsharpAST.js";
5
+ import { defaultArg, unwrap } from "../../fable_modules/fable-library-js.5.17.2/Option.js";
6
+ import { map, tryFind } from "../../fable_modules/fable-library-js.5.17.2/List.js";
7
+ import { substring } from "../../fable_modules/fable-library-js.5.17.2/String.js";
8
+ import { tryUnwrapOption } from "./Utils.js";
9
+
10
+ export class SealedTypeInfo extends Record {
11
+ constructor(TypeParameterName, FSharpType) {
12
+ super();
13
+ this.TypeParameterName = TypeParameterName;
14
+ this.FSharpType = FSharpType;
15
+ }
16
+ }
17
+
18
+ export function SealedTypeInfo_$reflection() {
19
+ return record_type("Glutinum.Converter.Transformer.TypeParameter.SealedTypeInfo", [], SealedTypeInfo, () => [["TypeParameterName", string_type], ["FSharpType", FSharpType_$reflection()]]);
20
+ }
21
+
22
+ export class TransformResult extends Record {
23
+ constructor(FSharpTypeParameter, SealedTypeOpt) {
24
+ super();
25
+ this.FSharpTypeParameter = FSharpTypeParameter;
26
+ this.SealedTypeOpt = SealedTypeOpt;
27
+ }
28
+ }
29
+
30
+ export function TransformResult_$reflection() {
31
+ return record_type("Glutinum.Converter.Transformer.TypeParameter.TransformResult", [], TransformResult, () => [["FSharpTypeParameter", FSharpTypeParameter_$reflection()], ["SealedTypeOpt", option_type(SealedTypeInfo_$reflection())]]);
32
+ }
33
+
34
+ export function TransformResult_Create_403667D8(typeParameterName, default_, constraint_, sealedType) {
35
+ return new TransformResult(new FSharpTypeParameter(/* FSharpTypeParameter */ 1, [FSharpTypeParameterInfo_Create_Z6CFD3565(typeParameterName, unwrap(constraint_), unwrap(default_))]), (sealedType == null) ? undefined : (new SealedTypeInfo(typeParameterName, sealedType)));
36
+ }
37
+
38
+ /**
39
+ * `withDefault` transforms the default, which exposes the types it names. A signature
40
+ * never prints a default, F# has none, and exposing them there names the type parameters
41
+ * of the enclosing declaration, which the exposed type can't declare.
42
+ */
43
+ export function mapFSharpType(seadledTypes, typ) {
44
+ let matchResult, typeParameter, info_1, info_2, innerType, typeReference, unionInfo, types, typ_7, functionInfo, alias;
45
+ switch (typ.tag) {
46
+ case 0:
47
+ case 2:
48
+ case 4:
49
+ case 5:
50
+ case 6:
51
+ case 8:
52
+ case 10:
53
+ case 15:
54
+ case 17:
55
+ case 18:
56
+ case 19:
57
+ case 20:
58
+ case 21: {
59
+ matchResult = 10;
60
+ break;
61
+ }
62
+ case 7: {
63
+ if (typ.fields[0].Name.startsWith("\'")) {
64
+ matchResult = 1;
65
+ info_1 = typ.fields[0];
66
+ }
67
+ else {
68
+ matchResult = 2;
69
+ info_2 = typ.fields[0];
70
+ }
71
+ break;
72
+ }
73
+ case 3: {
74
+ matchResult = 3;
75
+ innerType = typ.fields[0];
76
+ break;
77
+ }
78
+ case 11: {
79
+ matchResult = 4;
80
+ typeReference = typ.fields[0];
81
+ break;
82
+ }
83
+ case 1: {
84
+ matchResult = 5;
85
+ unionInfo = typ.fields[0];
86
+ break;
87
+ }
88
+ case 12: {
89
+ matchResult = 6;
90
+ types = typ.fields[0];
91
+ break;
92
+ }
93
+ case 14: {
94
+ matchResult = 7;
95
+ typ_7 = typ.fields[0];
96
+ break;
97
+ }
98
+ case 16: {
99
+ matchResult = 8;
100
+ functionInfo = typ.fields[0];
101
+ break;
102
+ }
103
+ case 9: {
104
+ matchResult = 9;
105
+ alias = typ.fields[0];
106
+ break;
107
+ }
108
+ default: {
109
+ matchResult = 0;
110
+ typeParameter = typ.fields[0];
111
+ }
112
+ }
113
+ switch (matchResult) {
114
+ case 0: {
115
+ const needMapping = tryFind((mapperInfo) => (mapperInfo.TypeParameterName === typeParameter), seadledTypes);
116
+ if (needMapping == null) {
117
+ return typ;
118
+ }
119
+ else {
120
+ return needMapping.FSharpType;
121
+ }
122
+ }
123
+ case 1: {
124
+ const matchValue = tryFind((mapperInfo_2) => (mapperInfo_2.TypeParameterName === substring(info_1.Name, 1)), seadledTypes);
125
+ if (matchValue == null) {
126
+ return typ;
127
+ }
128
+ else {
129
+ return matchValue.FSharpType;
130
+ }
131
+ }
132
+ case 2:
133
+ return new FSharpType(/* Mapped */ 7, [new FSharpMapped(info_2.Name, map((_arg) => {
134
+ if (_arg.tag === 1) {
135
+ const paramInfo = _arg.fields[0];
136
+ const matchValue_1 = tryFind((mapperInfo_4) => (mapperInfo_4.TypeParameterName === paramInfo.Name), seadledTypes);
137
+ if (matchValue_1 == null) {
138
+ return new FSharpTypeParameter(/* FSharpTypeParameter */ 1, [paramInfo]);
139
+ }
140
+ else {
141
+ return new FSharpTypeParameter(/* FSharpType */ 0, [matchValue_1.FSharpType]);
142
+ }
143
+ }
144
+ else {
145
+ return new FSharpTypeParameter(/* FSharpType */ 0, [mapFSharpType(seadledTypes, _arg.fields[0])]);
146
+ }
147
+ }, info_2.TypeParameters))]);
148
+ case 3:
149
+ return new FSharpType(/* Option */ 3, [mapFSharpType(seadledTypes, innerType)]);
150
+ case 4:
151
+ return new FSharpType(/* TypeReference */ 11, [new FSharpTypeReference(typeReference.Name, typeReference.FullName, typeReference.ModulePath, map((typ_2) => mapFSharpType(seadledTypes, typ_2), typeReference.TypeArguments), typeReference.Type)]);
152
+ case 5:
153
+ return new FSharpType(/* Union */ 1, [new FSharpUnion(unionInfo.Attributes, unionInfo.Name, map((case$) => {
154
+ switch (case$.tag) {
155
+ case 1:
156
+ return new FSharpUnionCase(/* Typed */ 1, [mapFSharpType(seadledTypes, case$.fields[0])]);
157
+ case 2:
158
+ return new FSharpUnionCase(/* Field */ 2, [case$.fields[0], mapFSharpType(seadledTypes, case$.fields[1])]);
159
+ case 3:
160
+ return new FSharpUnionCase(/* NamedFields */ 3, [case$.fields[0], map((tupledArg) => [tupledArg[0], mapFSharpType(seadledTypes, tupledArg[1])], case$.fields[1])]);
161
+ default:
162
+ return case$;
163
+ }
164
+ }, unionInfo.Cases), unionInfo.IsOptional, unionInfo.TypeParameters, unionInfo.Constants)]);
165
+ case 6:
166
+ return new FSharpType(/* Tuple */ 12, [map((typ_6) => mapFSharpType(seadledTypes, typ_6), types)]);
167
+ case 7:
168
+ return new FSharpType(/* ResizeArray */ 14, [mapFSharpType(seadledTypes, typ_7)]);
169
+ case 8:
170
+ return new FSharpType(/* Function */ 16, [new FSharpFunctionType(map((parameter) => mapFsharpParameter(seadledTypes, parameter), functionInfo.Parameters), mapFSharpType(seadledTypes, functionInfo.ReturnType))]);
171
+ case 9:
172
+ return new FSharpType(/* TypeAlias */ 9, [new FSharpTypeAlias(alias.Attributes, alias.Name, alias.XmlDoc, alias.Type, map((_arg_1) => {
173
+ if (_arg_1.tag === 0) {
174
+ return new FSharpTypeParameter(/* FSharpType */ 0, [mapFSharpType(seadledTypes, _arg_1.fields[0])]);
175
+ }
176
+ else {
177
+ const matchValue_2 = tryFind((mapperInfo_6) => (mapperInfo_6.TypeParameterName === _arg_1.fields[0].Name), seadledTypes);
178
+ if (matchValue_2 == null) {
179
+ return _arg_1;
180
+ }
181
+ else {
182
+ return new FSharpTypeParameter(/* FSharpType */ 0, [matchValue_2.FSharpType]);
183
+ }
184
+ }
185
+ }, alias.TypeParameters))]);
186
+ default:
187
+ return typ;
188
+ }
189
+ }
190
+
191
+ export function mapFsharpParameter(seadledTypes, parameter) {
192
+ const typ = mapFSharpType(seadledTypes, parameter.Type);
193
+ return new FSharpParameter(parameter.Attributes, parameter.Name, parameter.IsOptional, parameter.IsOptional ? defaultArg(tryUnwrapOption(typ), typ) : typ, parameter.OriginalGlueMember);
194
+ }
195
+
196
+ export class TransformTypeParametersResult extends Record {
197
+ constructor(TypeParameters, SealedTypes) {
198
+ super();
199
+ this.TypeParameters = TypeParameters;
200
+ this.SealedTypes = SealedTypes;
201
+ }
202
+ }
203
+
204
+ export function TransformTypeParametersResult_$reflection() {
205
+ return record_type("Glutinum.Converter.Transformer.TypeParameter.TransformTypeParametersResult", [], TransformTypeParametersResult, () => [["TypeParameters", list_type(FSharpTypeParameter_$reflection())], ["SealedTypes", list_type(SealedTypeInfo_$reflection())]]);
206
+ }
207
+
208
+ export class TransformDeclarationTypeParametersResult extends Record {
209
+ constructor(TypeParameters, SealedTypeArguments) {
210
+ super();
211
+ this.TypeParameters = TypeParameters;
212
+ this.SealedTypeArguments = SealedTypeArguments;
213
+ }
214
+ }
215
+
216
+ export function TransformDeclarationTypeParametersResult_$reflection() {
217
+ return record_type("Glutinum.Converter.Transformer.TypeParameter.TransformDeclarationTypeParametersResult", [], TransformDeclarationTypeParametersResult, () => [["TypeParameters", list_type(FSharpTypeParameter_$reflection())], ["SealedTypeArguments", option_type(list_type(FSharpTypeParameter_$reflection()))]]);
218
+ }
219
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glutinum/cli",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.8",
4
4
  "description": "TypeScript definition to F# bindings converter",
5
5
  "type": "module",
6
6
  "main": "index.js",