kodingo-cli 1.1.2 → 1.1.3
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/utils/ast-parser.js
CHANGED
|
@@ -142,6 +142,45 @@ function extractCallNames(node, acc = new Set()) {
|
|
|
142
142
|
walk(node);
|
|
143
143
|
return Array.from(acc);
|
|
144
144
|
}
|
|
145
|
+
const ROUTE_HTTP_METHODS = new Set(["get", "post", "put", "patch", "delete", "all"]);
|
|
146
|
+
function extractRoutes(node) {
|
|
147
|
+
const routes = [];
|
|
148
|
+
function walk(n) {
|
|
149
|
+
if (!n || typeof n !== "object")
|
|
150
|
+
return;
|
|
151
|
+
if (n.type === "CallExpression") {
|
|
152
|
+
const callee = n.callee;
|
|
153
|
+
if (callee?.type === "MemberExpression" &&
|
|
154
|
+
ROUTE_HTTP_METHODS.has(callee.property?.name?.toLowerCase())) {
|
|
155
|
+
const firstArg = n.arguments?.[0];
|
|
156
|
+
if (firstArg?.type === "Literal" && typeof firstArg.value === "string" &&
|
|
157
|
+
firstArg.value.startsWith("/")) {
|
|
158
|
+
routes.push({ method: callee.property.name.toUpperCase(), path: firstArg.value });
|
|
159
|
+
}
|
|
160
|
+
if (firstArg?.type === "TemplateLiteral") {
|
|
161
|
+
const raw = firstArg.quasis?.map((q) => q.value?.raw ?? "").join("*") ?? "";
|
|
162
|
+
if (raw.startsWith("/")) {
|
|
163
|
+
routes.push({ method: callee.property.name.toUpperCase(), path: raw });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
for (const key of Object.keys(n)) {
|
|
169
|
+
if (key === "parent")
|
|
170
|
+
continue;
|
|
171
|
+
const child = n[key];
|
|
172
|
+
if (Array.isArray(child)) {
|
|
173
|
+
for (const c of child)
|
|
174
|
+
walk(c);
|
|
175
|
+
}
|
|
176
|
+
else if (child && typeof child === "object" && child.type) {
|
|
177
|
+
walk(child);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
walk(node);
|
|
182
|
+
return routes;
|
|
183
|
+
}
|
|
145
184
|
async function parseTypeScript(filePath, source) {
|
|
146
185
|
try {
|
|
147
186
|
const parse = tsParse;
|
|
@@ -173,6 +212,7 @@ async function parseTypeScript(filePath, source) {
|
|
|
173
212
|
body,
|
|
174
213
|
fingerprint: computeFingerprint(body),
|
|
175
214
|
calls: extractCallNames(node.body),
|
|
215
|
+
routes: extractRoutes(node.body),
|
|
176
216
|
imports: fileImports,
|
|
177
217
|
});
|
|
178
218
|
}
|
|
@@ -190,6 +230,7 @@ async function parseTypeScript(filePath, source) {
|
|
|
190
230
|
body,
|
|
191
231
|
fingerprint: computeFingerprint(body),
|
|
192
232
|
calls: extractCallNames(node.init.body),
|
|
233
|
+
routes: extractRoutes(node.init.body),
|
|
193
234
|
imports: fileImports,
|
|
194
235
|
});
|
|
195
236
|
}
|
|
@@ -207,6 +248,7 @@ async function parseTypeScript(filePath, source) {
|
|
|
207
248
|
body,
|
|
208
249
|
fingerprint: computeFingerprint(body),
|
|
209
250
|
calls: extractCallNames(node.body),
|
|
251
|
+
routes: extractRoutes(node.body),
|
|
210
252
|
imports: fileImports,
|
|
211
253
|
});
|
|
212
254
|
// Visit methods inside the class
|
|
@@ -225,6 +267,7 @@ async function parseTypeScript(filePath, source) {
|
|
|
225
267
|
body: mBody,
|
|
226
268
|
fingerprint: computeFingerprint(mBody),
|
|
227
269
|
calls: extractCallNames(member.value?.body),
|
|
270
|
+
routes: extractRoutes(member.value?.body),
|
|
228
271
|
imports: fileImports,
|
|
229
272
|
});
|
|
230
273
|
}
|
|
@@ -299,6 +342,7 @@ function parseStructural(filePath, source, patterns) {
|
|
|
299
342
|
body,
|
|
300
343
|
fingerprint: computeFingerprint(body),
|
|
301
344
|
calls: extractCallNamesRegex(body),
|
|
345
|
+
routes: [],
|
|
302
346
|
imports: [],
|
|
303
347
|
});
|
|
304
348
|
break;
|
|
@@ -344,6 +388,7 @@ function parsePython(filePath, source) {
|
|
|
344
388
|
body,
|
|
345
389
|
fingerprint: computeFingerprint(body),
|
|
346
390
|
calls: extractCallNamesRegex(body),
|
|
391
|
+
routes: [],
|
|
347
392
|
imports: [],
|
|
348
393
|
});
|
|
349
394
|
}
|