create-caspian-app 0.0.21 → 0.0.22
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/dist/settings/component-map.ts +44 -11
- package/package.json +1 -1
|
@@ -71,7 +71,7 @@ function extractDictKeysFromNode(node: Parser.SyntaxNode): string[] {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
* Extracts values from a Literal[...]
|
|
74
|
+
* Extracts values from a Literal[...] or types from Union[...] node
|
|
75
75
|
*/
|
|
76
76
|
function extractLiteralValues(node: Parser.SyntaxNode): string[] {
|
|
77
77
|
const values: string[] = [];
|
|
@@ -85,19 +85,52 @@ function extractLiteralValues(node: Parser.SyntaxNode): string[] {
|
|
|
85
85
|
typeName = node.children.find((c) => c.type === "identifier")?.text;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
// --- Handle Literal[...] ---
|
|
89
|
+
if (typeName === "Literal") {
|
|
90
|
+
const findValues = (n: Parser.SyntaxNode) => {
|
|
91
|
+
if (n.type === "string") {
|
|
92
|
+
// Strip quotes from strings
|
|
93
|
+
values.push(n.text.replace(/^['"]|['"]$/g, ""));
|
|
94
|
+
} else if (
|
|
95
|
+
["integer", "float", "true", "false", "none"].includes(n.type)
|
|
96
|
+
) {
|
|
97
|
+
// Capture raw values for primitives (e.g. Literal[1, True, None])
|
|
98
|
+
values.push(n.text);
|
|
99
|
+
}
|
|
100
|
+
for (const child of n.children) {
|
|
101
|
+
findValues(child);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
findValues(node);
|
|
105
|
+
}
|
|
89
106
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
107
|
+
// --- Handle Union[...] ---
|
|
108
|
+
else if (typeName === "Union") {
|
|
109
|
+
for (const child of node.children) {
|
|
110
|
+
// Skip the "Union" keyword itself and punctuation
|
|
111
|
+
if (
|
|
112
|
+
(child.type === "identifier" && child.text === "Union") ||
|
|
113
|
+
["[", "]", ","].includes(child.type)
|
|
114
|
+
) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Capture Types (bool, str, etc.) and None
|
|
119
|
+
if (
|
|
120
|
+
child.type === "identifier" ||
|
|
121
|
+
child.type === "none" ||
|
|
122
|
+
child.type === "type" ||
|
|
123
|
+
child.type === "primitive_type"
|
|
124
|
+
) {
|
|
125
|
+
values.push(child.text);
|
|
126
|
+
}
|
|
127
|
+
// Recursively handle nested structures (e.g. Union[str, Literal["a"]])
|
|
128
|
+
else if (child.type === "subscript" || child.type === "generic_type") {
|
|
129
|
+
values.push(...extractLiteralValues(child));
|
|
130
|
+
}
|
|
97
131
|
}
|
|
98
|
-
}
|
|
132
|
+
}
|
|
99
133
|
|
|
100
|
-
findStrings(node);
|
|
101
134
|
return values;
|
|
102
135
|
}
|
|
103
136
|
|