@glutinum/cli 1.0.0-beta.7 → 1.0.0-beta.9

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.
@@ -0,0 +1,706 @@
1
+
2
+ import { primitiveOfFlags, entityNameText, mainDeclaration, typeNodeBuilderFlags, enclosingDeclarationOf, resolveAlias, symbolAtLocation, identifierText, $007CHasTypeFlags$007C_$007C } from "./Utils.js";
3
+ import { Operators_IsNull } from "../../fable_modules/fable-library-js.5.17.2/FSharp.Core.js";
4
+ import { length, truncate, isEmpty, exists as exists_1, choose, cons, collect as collect_1, singleton, tryFind, fold, append, empty, reverse } from "../../fable_modules/fable-library-js.5.17.2/List.js";
5
+ import { toArray, defaultArg, value as value_1 } from "../../fable_modules/fable-library-js.5.17.2/Option.js";
6
+ import { tryHead, tryFindIndex, collect as collect_2, empty as empty_3, singleton as singleton_1, append as append_1, delay, filter, map, exists, toList } from "../../fable_modules/fable-library-js.5.17.2/Seq.js";
7
+ import { FSharpMap__get_Count, FSharpMap__get_Values, FSharpMap__TryFind, empty as empty_1, FSharpMap__ContainsKey, FSharpMap__Add } from "../../fable_modules/fable-library-js.5.17.2/Map.js";
8
+ import { comparePrimitives } from "../../fable_modules/fable-library-js.5.17.2/Util.js";
9
+ import { ts } from "@ts-morph/bootstrap";
10
+ import { empty as empty_2, FSharpSet__Add, FSharpSet__Contains } from "../../fable_modules/fable-library-js.5.17.2/Set.js";
11
+ import { GlueClassDeclaration, GluePrimitive, GlueType } from "../GlueAST.js";
12
+ import { item } from "../../fable_modules/fable-library-js.5.17.2/Array.js";
13
+
14
+ /**
15
+ * A conditional type the checker can't resolve without its type arguments
16
+ */
17
+ export function isDeferredConditional(typ) {
18
+ const matchValue = typ.flags;
19
+ if ($007CHasTypeFlags$007C_$007C(67108864, matchValue) != null) {
20
+ return true;
21
+ }
22
+ else {
23
+ return false;
24
+ }
25
+ }
26
+
27
+ function isParseTreeNode(node) {
28
+ return (node.flags & 16) === 0;
29
+ }
30
+
31
+ function typeParametersInScope(reader, typeNode) {
32
+ const collect = (node_mut, acc_mut) => {
33
+ collect:
34
+ while (true) {
35
+ const node = node_mut, acc = acc_mut;
36
+ let option_1;
37
+ if (Operators_IsNull(node)) {
38
+ return reverse(acc);
39
+ }
40
+ else if (((Operators_IsNull(node.parent) && (node.pos < 0)) && (reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_SyntheticContext"]() != null)) && !(node === value_1(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_SyntheticContext"]()))) {
41
+ node_mut = value_1(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_SyntheticContext"]());
42
+ acc_mut = acc;
43
+ continue collect;
44
+ }
45
+ else if (node.kind === 266) {
46
+ return reverse(acc);
47
+ }
48
+ else {
49
+ const own_1 = defaultArg((option_1 = (isParseTreeNode(node) ? node.typeParameters : undefined), (option_1 != null) ? toList(option_1) : undefined), empty());
50
+ node_mut = node.parent;
51
+ acc_mut = append(reverse(own_1), acc);
52
+ continue collect;
53
+ }
54
+ break;
55
+ }
56
+ };
57
+ return collect(typeNode.parent, empty());
58
+ }
59
+
60
+ function isDeclaredByType(typeParameter) {
61
+ const parent = typeParameter.parent;
62
+ if (!Operators_IsNull(parent)) {
63
+ const matchValue = parent.kind;
64
+ switch (matchValue) {
65
+ case 232:
66
+ case 264:
67
+ case 265:
68
+ return true;
69
+ default:
70
+ return false;
71
+ }
72
+ }
73
+ else {
74
+ return false;
75
+ }
76
+ }
77
+
78
+ function boundTypeParameters(reader, typeNode) {
79
+ return fold((bound, typeParameter) => {
80
+ let constraint_, default_;
81
+ const name = identifierText(typeParameter.name);
82
+ let binding;
83
+ const matchValue = typeParameter.default;
84
+ const matchValue_1 = typeParameter.constraint;
85
+ let matchResult, default__1, constraint__1;
86
+ if (matchValue == null) {
87
+ if (matchValue_1 != null) {
88
+ if ((constraint_ = matchValue_1, constraint_.kind !== 199)) {
89
+ matchResult = 2;
90
+ constraint__1 = matchValue_1;
91
+ }
92
+ else {
93
+ matchResult = 3;
94
+ }
95
+ }
96
+ else {
97
+ matchResult = 3;
98
+ }
99
+ }
100
+ else if ((default_ = matchValue, isDeclaredByType(typeParameter) && (default_.kind !== 133))) {
101
+ matchResult = 0;
102
+ default__1 = matchValue;
103
+ }
104
+ else {
105
+ matchResult = 1;
106
+ }
107
+ switch (matchResult) {
108
+ case 0: {
109
+ binding = default__1;
110
+ break;
111
+ }
112
+ case 1: {
113
+ binding = undefined;
114
+ break;
115
+ }
116
+ case 2: {
117
+ binding = constraint__1;
118
+ break;
119
+ }
120
+ default:
121
+ binding = undefined;
122
+ }
123
+ let matchResult_1, binding_2;
124
+ if (binding != null) {
125
+ if (!FSharpMap__ContainsKey(bound, name)) {
126
+ matchResult_1 = 0;
127
+ binding_2 = binding;
128
+ }
129
+ else {
130
+ matchResult_1 = 1;
131
+ }
132
+ }
133
+ else {
134
+ matchResult_1 = 1;
135
+ }
136
+ switch (matchResult_1) {
137
+ case 0:
138
+ return FSharpMap__Add(bound, name, binding_2);
139
+ default:
140
+ return bound;
141
+ }
142
+ }, empty_1({
143
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
144
+ }), typeParametersInScope(reader, typeNode));
145
+ }
146
+
147
+ /**
148
+ * `T` of `JSHandle<T = any>`
149
+ */
150
+ export function isAnyTypeParameter(reader, typeNode) {
151
+ let option_1, _arg;
152
+ if (typeNode.kind === 184) {
153
+ const typeName = typeNode.typeName;
154
+ if (typeName.kind === 80) {
155
+ return exists((default_) => (default_.kind === 133), toArray((option_1 = tryFind((typeParameter) => (identifierText(typeParameter.name) === identifierText(typeName)), typeParametersInScope(reader, typeNode)), (option_1 != null) ? ((_arg = option_1, _arg.default)) : undefined)));
156
+ }
157
+ else {
158
+ return false;
159
+ }
160
+ }
161
+ else {
162
+ return false;
163
+ }
164
+ }
165
+
166
+ function mentionsBoundTypeParameter(bindings, typeNode) {
167
+ let option_1;
168
+ const mentions = (typeNode_1) => mentionsBoundTypeParameter(bindings, typeNode_1);
169
+ const matchValue = typeNode.kind;
170
+ switch (matchValue) {
171
+ case 184: {
172
+ const typeReferenceNode = typeNode;
173
+ const typeName = typeReferenceNode.typeName;
174
+ if ((typeName.kind === 80) && FSharpMap__ContainsKey(bindings, identifierText(typeName))) {
175
+ return true;
176
+ }
177
+ else {
178
+ return defaultArg((option_1 = typeReferenceNode.typeArguments, (option_1 != null) ? exists(mentions, option_1) : undefined), false);
179
+ }
180
+ }
181
+ case 189:
182
+ return mentions(typeNode.elementType);
183
+ case 193:
184
+ return exists(mentions, typeNode.types);
185
+ case 195: {
186
+ const conditionalTypeNode = typeNode;
187
+ if ((mentions(conditionalTypeNode.checkType) ? true : mentions(conditionalTypeNode.extendsType)) ? true : mentions(conditionalTypeNode.trueType)) {
188
+ return true;
189
+ }
190
+ else {
191
+ return mentions(conditionalTypeNode.falseType);
192
+ }
193
+ }
194
+ case 200: {
195
+ const indexedAccessTypeNode = typeNode;
196
+ if (mentions(indexedAccessTypeNode.objectType)) {
197
+ return true;
198
+ }
199
+ else {
200
+ return mentions(indexedAccessTypeNode.indexType);
201
+ }
202
+ }
203
+ default:
204
+ return false;
205
+ }
206
+ }
207
+
208
+ function substituteBoundTypeParameters(bindings, typeNode) {
209
+ const substitute = (typeNode_1) => substituteBoundTypeParameters(bindings, typeNode_1);
210
+ const adopt = (synthesized) => ((function (ts, node, like, flag) {
211
+ Object.assign(node, { flags: node.flags & ~flag, pos: like.pos, end: like.end, parent: like.parent });
212
+ ts.forEachChild(node, function (child) {
213
+ if ((child.flags & flag) !== 0 && !child.parent) {
214
+ Object.assign(child, { flags: child.flags & ~flag, pos: like.pos, end: like.end, parent: node });
215
+ }
216
+ });
217
+ return node;
218
+ })(ts, synthesized, typeNode, 16));
219
+ const matchValue = typeNode.kind;
220
+ switch (matchValue) {
221
+ case 184: {
222
+ const typeReferenceNode = typeNode;
223
+ const typeName = typeReferenceNode.typeName;
224
+ const matchValue_1 = typeReferenceNode.typeArguments;
225
+ if (matchValue_1 != null) {
226
+ const typeArguments = matchValue_1;
227
+ return adopt((ts.factory).createTypeReferenceNode(typeReferenceNode.typeName, Array.from(map(substitute, typeArguments))));
228
+ }
229
+ else if (typeName.kind === 80) {
230
+ return defaultArg(FSharpMap__TryFind(bindings, identifierText(typeName)), typeNode);
231
+ }
232
+ else {
233
+ return typeNode;
234
+ }
235
+ }
236
+ case 189:
237
+ return adopt((ts.factory).createArrayTypeNode(substitute(typeNode.elementType)));
238
+ case 193:
239
+ return adopt((ts.factory).createUnionTypeNode(Array.from(map(substitute, typeNode.types))));
240
+ case 195: {
241
+ const conditionalTypeNode = typeNode;
242
+ return adopt((ts.factory).createConditionalTypeNode(substitute(conditionalTypeNode.checkType), substitute(conditionalTypeNode.extendsType), substitute(conditionalTypeNode.trueType), substitute(conditionalTypeNode.falseType)));
243
+ }
244
+ case 200: {
245
+ const indexedAccessTypeNode = typeNode;
246
+ return adopt((ts.factory).createIndexedAccessTypeNode(substitute(indexedAccessTypeNode.objectType), substitute(indexedAccessTypeNode.indexType)));
247
+ }
248
+ default:
249
+ return typeNode;
250
+ }
251
+ }
252
+
253
+ function deferredConditionals(checker, depth, typ) {
254
+ let depth_1;
255
+ const matchValue = typ.flags;
256
+ if ($007CHasTypeFlags$007C_$007C(67108864, matchValue) != null) {
257
+ return singleton(typ);
258
+ }
259
+ else {
260
+ let matchResult;
261
+ if ($007CHasTypeFlags$007C_$007C(134217728, matchValue) != null) {
262
+ matchResult = 0;
263
+ }
264
+ else if ($007CHasTypeFlags$007C_$007C(268435456, matchValue) != null) {
265
+ matchResult = 0;
266
+ }
267
+ else {
268
+ matchResult = 1;
269
+ }
270
+ switch (matchResult) {
271
+ case 0:
272
+ return collect_1((typ_1) => deferredConditionals(checker, depth, typ_1), toList(typ.types));
273
+ default: {
274
+ let matchResult_1;
275
+ if ($007CHasTypeFlags$007C_$007C(1048576, matchValue) != null) {
276
+ if ((depth < 8) && ((typ.objectFlags & 4) !== 0)) {
277
+ matchResult_1 = 0;
278
+ }
279
+ else {
280
+ matchResult_1 = 1;
281
+ }
282
+ }
283
+ else {
284
+ matchResult_1 = 1;
285
+ }
286
+ switch (matchResult_1) {
287
+ case 0:
288
+ return collect_1((depth_1 = ((depth + 1) | 0), (typ_2) => deferredConditionals(checker, depth_1, typ_2)), toList(checker.getTypeArguments(typ)));
289
+ default:
290
+ return empty();
291
+ }
292
+ }
293
+ }
294
+ }
295
+ }
296
+
297
+ function mentionedTypes(checker, depth, typ) {
298
+ let option_1, matchValue, indexedAccess, conditional;
299
+ let mentioned;
300
+ const depth_1 = (depth + 1) | 0;
301
+ mentioned = ((typ_1) => mentionedTypes(checker, depth_1, typ_1));
302
+ if (depth > 8) {
303
+ return empty();
304
+ }
305
+ else {
306
+ return append(cons(typ, defaultArg((option_1 = typ.aliasTypeArguments, (option_1 != null) ? collect_1(mentioned, toList(option_1)) : undefined), empty())), (matchValue = typ.flags, ($007CHasTypeFlags$007C_$007C(134217728, matchValue) != null) ? collect_1(mentioned, toList(typ.types)) : (($007CHasTypeFlags$007C_$007C(268435456, matchValue) != null) ? collect_1(mentioned, toList(typ.types)) : (($007CHasTypeFlags$007C_$007C(1048576, matchValue) != null) ? (((typ.objectFlags & 4) !== 0) ? collect_1(mentioned, toList(checker.getTypeArguments(typ))) : (($007CHasTypeFlags$007C_$007C(2097152, matchValue) != null) ? mentioned(typ.type) : (($007CHasTypeFlags$007C_$007C(33554432, matchValue) != null) ? ((indexedAccess = typ, append(mentioned(indexedAccess.objectType), mentioned(indexedAccess.indexType)))) : (($007CHasTypeFlags$007C_$007C(67108864, matchValue) != null) ? ((conditional = typ, append(mentioned(conditional.checkType), mentioned(conditional.extendsType)))) : empty())))) : (($007CHasTypeFlags$007C_$007C(2097152, matchValue) != null) ? mentioned(typ.type) : (($007CHasTypeFlags$007C_$007C(33554432, matchValue) != null) ? ((indexedAccess = typ, append(mentioned(indexedAccess.objectType), mentioned(indexedAccess.indexType)))) : (($007CHasTypeFlags$007C_$007C(67108864, matchValue) != null) ? ((conditional = typ, append(mentioned(conditional.checkType), mentioned(conditional.extendsType)))) : empty())))))));
307
+ }
308
+ }
309
+
310
+ function typeParameterNamesOf(checker, typ) {
311
+ return choose((mentioned) => {
312
+ const matchValue = mentioned.flags;
313
+ if ($007CHasTypeFlags$007C_$007C(524288, matchValue) != null) {
314
+ return mentioned.symbol.name;
315
+ }
316
+ else {
317
+ return undefined;
318
+ }
319
+ }, mentionedTypes(checker, 0, typ));
320
+ }
321
+
322
+ function isStillBound(checker, bound, typ) {
323
+ const substitutes = toList(map((node_1) => checker.getTypeFromTypeNode(node_1), filter((node) => (node.kind === 184), FSharpMap__get_Values(bound))));
324
+ const mentioned = mentionedTypes(checker, 0, typ);
325
+ return exists_1((substitute) => exists_1((typ_1) => (typ_1 === substitute), mentioned), substitutes);
326
+ }
327
+
328
+ function resolveWithBindings(checker_mut, typeNode_mut, bindings_mut, bound_mut, typ_mut) {
329
+ resolveWithBindings:
330
+ while (true) {
331
+ const checker = checker_mut, typeNode = typeNode_mut, bindings = bindings_mut, bound = bound_mut, typ = typ_mut;
332
+ const conditionals = deferredConditionals(checker, 0, typ);
333
+ if (isEmpty(conditionals)) {
334
+ if (isStillBound(checker, bound, typ)) {
335
+ return undefined;
336
+ }
337
+ else {
338
+ return typ;
339
+ }
340
+ }
341
+ else {
342
+ const alreadyBound = FSharpMap__get_Count(bound) | 0;
343
+ const bound_3 = fold((bound_1, conditional) => fold((bound_2, name) => {
344
+ const matchValue = FSharpMap__TryFind(bindings, name);
345
+ let matchResult, binding_1;
346
+ if (matchValue != null) {
347
+ if (!FSharpMap__ContainsKey(bound_2, name)) {
348
+ matchResult = 0;
349
+ binding_1 = matchValue;
350
+ }
351
+ else {
352
+ matchResult = 1;
353
+ }
354
+ }
355
+ else {
356
+ matchResult = 1;
357
+ }
358
+ switch (matchResult) {
359
+ case 0:
360
+ return FSharpMap__Add(bound_2, name, binding_1);
361
+ default:
362
+ return bound_2;
363
+ }
364
+ }, bound_1, append(typeParameterNamesOf(checker, conditional.checkType), typeParameterNamesOf(checker, conditional.extendsType))), bound, conditionals);
365
+ if ((FSharpMap__get_Count(bound_3) === alreadyBound) ? true : !mentionsBoundTypeParameter(bound_3, typeNode)) {
366
+ return undefined;
367
+ }
368
+ else {
369
+ checker_mut = checker;
370
+ typeNode_mut = typeNode;
371
+ bindings_mut = bindings;
372
+ bound_mut = bound_3;
373
+ typ_mut = checker.getTypeFromTypeNode(substituteBoundTypeParameters(bound_3, typeNode));
374
+ continue resolveWithBindings;
375
+ }
376
+ }
377
+ break;
378
+ }
379
+ }
380
+
381
+ function standsForConditional(checker_mut, visited_mut, node_mut) {
382
+ standsForConditional:
383
+ while (true) {
384
+ const checker = checker_mut, visited = visited_mut, node = node_mut;
385
+ let option_3;
386
+ const matchValue = node.kind;
387
+ switch (matchValue) {
388
+ case 184: {
389
+ const typeReferenceNode = node;
390
+ let matchValue_1;
391
+ const option_1 = symbolAtLocation(checker, typeReferenceNode.typeName);
392
+ matchValue_1 = ((option_1 != null) ? resolveAlias(checker, option_1) : undefined);
393
+ if (matchValue_1 == null) {
394
+ return false;
395
+ }
396
+ else {
397
+ const symbol_1 = matchValue_1;
398
+ const key = checker.getFullyQualifiedName(symbol_1);
399
+ if (!FSharpSet__Contains(visited, key)) {
400
+ return defaultArg((option_3 = symbol_1.declarations, (option_3 != null) ? exists((declaration) => {
401
+ if (declaration.kind === 266) {
402
+ return standsForConditional(checker, FSharpSet__Add(visited, key), declaration.type);
403
+ }
404
+ else {
405
+ return false;
406
+ }
407
+ }, option_3) : undefined), false);
408
+ }
409
+ else {
410
+ return false;
411
+ }
412
+ }
413
+ }
414
+ case 195:
415
+ return true;
416
+ case 197: {
417
+ checker_mut = checker;
418
+ visited_mut = visited;
419
+ node_mut = node.type;
420
+ continue standsForConditional;
421
+ }
422
+ default:
423
+ return false;
424
+ }
425
+ break;
426
+ }
427
+ }
428
+
429
+ function isWithinConstraint(node_mut) {
430
+ isWithinConstraint:
431
+ while (true) {
432
+ const node = node_mut;
433
+ if (Operators_IsNull(node) ? true : Operators_IsNull(node.parent)) {
434
+ return false;
435
+ }
436
+ else if (node.parent.kind === 169) {
437
+ const matchValue = node.parent.constraint;
438
+ if (matchValue == null) {
439
+ return false;
440
+ }
441
+ else {
442
+ return matchValue === node;
443
+ }
444
+ }
445
+ else {
446
+ node_mut = node.parent;
447
+ continue isWithinConstraint;
448
+ }
449
+ break;
450
+ }
451
+ }
452
+
453
+ /**
454
+ * `on<K>(event: Key<K, T>)` of `EventEmitter<T = DefaultEventMap>`: the checker defers
455
+ * `Key<K, T>`, it resolves `Key<K, DefaultEventMap>`. The type parameters the condition names
456
+ * are bound to their default or constraint, the ones the branches name only stay generic, and
457
+ * the checker is asked again. A condition revealed by a branch is bound in turn.
458
+ */
459
+ export function tryResolveDeferred(reader, typeNode) {
460
+ let resolvedNode, previousContext;
461
+ const checker = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"]();
462
+ const bindings = boundTypeParameters(reader, typeNode);
463
+ if (((!isParseTreeNode(typeNode) ? true : !standsForConditional(checker, empty_2({
464
+ Compare: (x, y) => (comparePrimitives(x, y) | 0),
465
+ }), typeNode)) ? true : isWithinConstraint(typeNode)) ? true : !mentionsBoundTypeParameter(bindings, typeNode)) {
466
+ return undefined;
467
+ }
468
+ else {
469
+ const typ = checker.getTypeAtLocation(typeNode);
470
+ if (isEmpty(deferredConditionals(checker, 0, typ))) {
471
+ return undefined;
472
+ }
473
+ else {
474
+ let option_3;
475
+ const option_1 = resolveWithBindings(checker, typeNode, bindings, empty_1({
476
+ Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
477
+ }), typ);
478
+ if (option_1 != null) {
479
+ const resolved = option_1;
480
+ option_3 = checker.typeToTypeNode(resolved, enclosingDeclarationOf(typeNode), typeNodeBuilderFlags);
481
+ }
482
+ else {
483
+ option_3 = undefined;
484
+ }
485
+ if (option_3 != null) {
486
+ return (resolvedNode = option_3, (previousContext = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_SyntheticContext"](), (reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.set_SyntheticContext"](typeNode), (() => {
487
+ try {
488
+ return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](resolvedNode);
489
+ }
490
+ finally {
491
+ reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.set_SyntheticContext"](previousContext);
492
+ }
493
+ })())));
494
+ }
495
+ else {
496
+ return undefined;
497
+ }
498
+ }
499
+ }
500
+ }
501
+
502
+ export function inferTypeNodes(node) {
503
+ return toList(delay(() => append_1((node.kind === 196) ? singleton_1(node) : empty_3(), delay(() => collect_2(inferTypeNodes, node.getChildren())))));
504
+ }
505
+
506
+ /**
507
+ * `Options<infer DateType>` stands for the constraint declared at its position, `Date` for
508
+ * `interface Options<DateType extends Date>`
509
+ */
510
+ export function inferredConstraint(reader, inferTypeNode) {
511
+ const matchValue_1 = inferTypeNode.typeParameter.constraint;
512
+ if (matchValue_1 == null) {
513
+ let atPosition;
514
+ if (inferTypeNode.parent.kind === 184) {
515
+ const typeReferenceNode = inferTypeNode.parent;
516
+ let position;
517
+ const option_1 = typeReferenceNode.typeArguments;
518
+ position = ((option_1 != null) ? tryFindIndex((typeArgument) => (typeArgument === inferTypeNode), option_1) : undefined);
519
+ let option_13;
520
+ let option_9;
521
+ let option_7;
522
+ let option_5;
523
+ const option_2 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"]().getSymbolAtLocation(typeReferenceNode.typeName);
524
+ let binder_2;
525
+ const checker = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"]();
526
+ binder_2 = ((symbol) => resolveAlias(checker, symbol));
527
+ const option_3 = option_2;
528
+ option_5 = ((option_3 != null) ? binder_2(option_3) : undefined);
529
+ if (option_5 != null) {
530
+ const symbol_1 = option_5;
531
+ option_7 = symbol_1.declarations;
532
+ }
533
+ else {
534
+ option_7 = undefined;
535
+ }
536
+ option_9 = ((option_7 != null) ? tryHead(option_7) : undefined);
537
+ if (option_9 != null) {
538
+ const declaration = option_9;
539
+ const matchValue = declaration.kind;
540
+ option_13 = ((matchValue === 264) ? declaration.typeParameters : ((matchValue === 265) ? declaration.typeParameters : ((matchValue === 266) ? declaration.typeParameters : undefined)));
541
+ }
542
+ else {
543
+ option_13 = undefined;
544
+ }
545
+ if (option_13 != null) {
546
+ const typeParameters = option_13;
547
+ const option_11 = position;
548
+ if (option_11 != null) {
549
+ const position_1 = option_11 | 0;
550
+ atPosition = ((position_1 < ~~typeParameters.length) ? (typeParameters[position_1]).constraint : undefined);
551
+ }
552
+ else {
553
+ atPosition = undefined;
554
+ }
555
+ }
556
+ else {
557
+ atPosition = undefined;
558
+ }
559
+ }
560
+ else {
561
+ atPosition = undefined;
562
+ }
563
+ if (atPosition == null) {
564
+ return GlueType.Unknown;
565
+ }
566
+ else {
567
+ const constraintNode_1 = atPosition;
568
+ return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](constraintNode_1);
569
+ }
570
+ }
571
+ else {
572
+ const constraintNode = matchValue_1;
573
+ return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](constraintNode);
574
+ }
575
+ }
576
+
577
+ export function truncateToDeclaredArity(reader, symbolOpt, typeArguments) {
578
+ let option_5, _arg;
579
+ let declaredArity;
580
+ let option_8;
581
+ let option_2;
582
+ let binder;
583
+ const checker = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"]();
584
+ binder = ((symbol) => resolveAlias(checker, symbol));
585
+ const option_1 = symbolOpt;
586
+ option_2 = ((option_1 != null) ? binder(option_1) : undefined);
587
+ let binder_2;
588
+ const packageContext = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_PackageContext"]();
589
+ binder_2 = ((symbol_1) => mainDeclaration(packageContext, symbol_1));
590
+ const option_3 = option_2;
591
+ option_8 = ((option_3 != null) ? binder_2(option_3) : undefined);
592
+ if (option_8 != null) {
593
+ const declaration = option_8;
594
+ const matchValue = declaration.kind;
595
+ switch (matchValue) {
596
+ case 264:
597
+ case 265:
598
+ case 266: {
599
+ declaredArity = defaultArg((option_5 = declaration.typeParameters, (option_5 != null) ? ((_arg = option_5, ~~_arg.length)) : undefined), 0);
600
+ break;
601
+ }
602
+ default:
603
+ declaredArity = undefined;
604
+ }
605
+ }
606
+ else {
607
+ declaredArity = undefined;
608
+ }
609
+ let matchResult, arity_1;
610
+ if (declaredArity != null) {
611
+ if (declaredArity < length(typeArguments)) {
612
+ matchResult = 0;
613
+ arity_1 = declaredArity;
614
+ }
615
+ else {
616
+ matchResult = 1;
617
+ }
618
+ }
619
+ else {
620
+ matchResult = 1;
621
+ }
622
+ switch (matchResult) {
623
+ case 0:
624
+ return truncate(arity_1, typeArguments);
625
+ default:
626
+ return typeArguments;
627
+ }
628
+ }
629
+
630
+ export function isGlobalThisQuery(typeNode) {
631
+ if (typeNode.kind === 187) {
632
+ return entityNameText(typeNode.exprName) === "globalThis";
633
+ }
634
+ else {
635
+ return false;
636
+ }
637
+ }
638
+
639
+ export function readTypeUsingFlags(reader, typ) {
640
+ let declarations;
641
+ const matchValue = typ.flags;
642
+ let matchResult;
643
+ if ($007CHasTypeFlags$007C_$007C(1048576, matchValue) != null) {
644
+ if (Operators_IsNull(typ.symbol)) {
645
+ matchResult = 0;
646
+ }
647
+ else {
648
+ matchResult = 1;
649
+ }
650
+ }
651
+ else {
652
+ matchResult = 1;
653
+ }
654
+ switch (matchResult) {
655
+ case 0:
656
+ return new GlueType(/* Primitive */ 3, [GluePrimitive.Any]);
657
+ default:
658
+ if ($007CHasTypeFlags$007C_$007C(1048576, matchValue) != null) {
659
+ const matchValue_1 = typ.symbol.declarations;
660
+ let matchResult_1, declarations_1;
661
+ if (matchValue_1 != null) {
662
+ if ((declarations = matchValue_1, declarations.length > 0)) {
663
+ matchResult_1 = 0;
664
+ declarations_1 = matchValue_1;
665
+ }
666
+ else {
667
+ matchResult_1 = 1;
668
+ }
669
+ }
670
+ else {
671
+ matchResult_1 = 1;
672
+ }
673
+ switch (matchResult_1) {
674
+ case 0: {
675
+ const declaration = item(0, declarations_1);
676
+ const matchValue_2 = declaration.kind;
677
+ switch (matchValue_2) {
678
+ case 264:
679
+ return new GlueType(/* ClassDeclaration */ 12, [new GlueClassDeclaration(empty(), reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"]().getFullyQualifiedName(typ.symbol), typ.symbol.name, empty(), empty(), empty(), empty(), true)]);
680
+ case 265:
681
+ case 266: {
682
+ const matchValue_3 = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"]().typeToTypeNode(typ, undefined, typeNodeBuilderFlags);
683
+ if (matchValue_3 == null) {
684
+ return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadNode6C0FD055"](declaration);
685
+ }
686
+ else {
687
+ const typeNode = matchValue_3;
688
+ return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](typeNode);
689
+ }
690
+ }
691
+ case 268:
692
+ return GlueType.Discard;
693
+ default:
694
+ return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadNode6C0FD055"](declaration);
695
+ }
696
+ }
697
+ default:
698
+ return new GlueType(/* Primitive */ 3, [GluePrimitive.Any]);
699
+ }
700
+ }
701
+ else {
702
+ return primitiveOfFlags(typ);
703
+ }
704
+ }
705
+ }
706
+