@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.
@@ -0,0 +1,90 @@
1
+
2
+ import { readTypeUsingFlags, inferTypeNodes, inferredConstraint, tryResolveDeferred, isAnyTypeParameter, isDeferredConditional } from "./Deferred.js";
3
+ import { GlueLiteral, GlueConditionalType, GlueTypeParameter, GlueTypeUnion, GlueType, GluePrimitive } from "../GlueAST.js";
4
+ import { stringHash, equals } from "../../fable_modules/fable-library-js.5.17.2/Util.js";
5
+ import { map, ofArray } from "../../fable_modules/fable-library-js.5.17.2/List.js";
6
+ import { List_distinctBy } from "../../fable_modules/fable-library-js.5.17.2/Seq2.js";
7
+ import { $007CHasTypeFlags$007C_$007C } from "./Utils.js";
8
+
9
+ export function readConditionalType(reader, typeNode) {
10
+ let branch, trueType, falseType;
11
+ const checker = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_checker"]();
12
+ const conditionalTypeNode = typeNode;
13
+ const typ = checker.getTypeAtLocation(conditionalTypeNode);
14
+ if (isDeferredConditional(typ)) {
15
+ const resolved = isAnyTypeParameter(reader, conditionalTypeNode.checkType) ? ((branch = ((node) => {
16
+ const matchValue = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](node);
17
+ let matchResult, glueType;
18
+ if (matchValue.tag === 8) {
19
+ if (matchValue.fields[0].tag === 4) {
20
+ matchResult = 0;
21
+ }
22
+ else {
23
+ matchResult = 1;
24
+ glueType = matchValue;
25
+ }
26
+ }
27
+ else {
28
+ matchResult = 1;
29
+ glueType = matchValue;
30
+ }
31
+ switch (matchResult) {
32
+ case 0:
33
+ return new GlueType(/* Primitive */ 3, [GluePrimitive.Null]);
34
+ default:
35
+ return glueType;
36
+ }
37
+ }), (trueType = branch(conditionalTypeNode.trueType), (falseType = branch(conditionalTypeNode.falseType), equals(trueType, falseType) ? trueType : (new GlueType(/* Union */ 7, [new GlueTypeUnion(ofArray([trueType, falseType]))])))))) : tryResolveDeferred(reader, typeNode);
38
+ if (resolved == null) {
39
+ const warningsCount = reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]().length | 0;
40
+ const inferred = List_distinctBy((_arg) => _arg.Name, map((inferTypeNode) => (new GlueTypeParameter(inferTypeNode.typeParameter.name.getText(), inferredConstraint(reader, inferTypeNode), undefined)), inferTypeNodes(conditionalTypeNode.extendsType)), {
41
+ Equals: (x, y) => (x === y),
42
+ GetHashCode: (x) => (stringHash(x) | 0),
43
+ });
44
+ const conditionalType = new GlueConditionalType(reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](conditionalTypeNode.checkType), reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](conditionalTypeNode.extendsType), reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](conditionalTypeNode.trueType), reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](conditionalTypeNode.falseType), inferred);
45
+ if (reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]().length > warningsCount) {
46
+ reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]().splice(warningsCount, reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.get_Warnings"]().length - warningsCount);
47
+ return new GlueType(/* Primitive */ 3, [GluePrimitive.Any]);
48
+ }
49
+ else {
50
+ return new GlueType(/* ConditionalType */ 33, [conditionalType]);
51
+ }
52
+ }
53
+ else {
54
+ return resolved;
55
+ }
56
+ }
57
+ else {
58
+ const matchValue_1 = typ.flags;
59
+ if ($007CHasTypeFlags$007C_$007C(524288, matchValue_1) != null) {
60
+ return new GlueType(/* TypeParameter */ 16, [typ.symbol.name]);
61
+ }
62
+ else if ($007CHasTypeFlags$007C_$007C(8192, matchValue_1) != null) {
63
+ return new GlueType(/* Literal */ 8, [new GlueLiteral(/* Bool */ 3, [typ.intrinsicName === "true"])]);
64
+ }
65
+ else {
66
+ const matchValue_2 = readTypeUsingFlags(reader, typ);
67
+ let matchResult_1, forward;
68
+ if (matchValue_2.tag === 3) {
69
+ if (matchValue_2.fields[0].tag === 6) {
70
+ matchResult_1 = 0;
71
+ }
72
+ else {
73
+ matchResult_1 = 1;
74
+ forward = matchValue_2;
75
+ }
76
+ }
77
+ else {
78
+ matchResult_1 = 1;
79
+ forward = matchValue_2;
80
+ }
81
+ switch (matchResult_1) {
82
+ case 0:
83
+ return reader["Glutinum.Converter.Reader.Types.ITypeScriptReader.ReadTypeNode24A678AD"](conditionalTypeNode.checkType);
84
+ default:
85
+ return forward;
86
+ }
87
+ }
88
+ }
89
+ }
90
+