@rayburst/cli 0.2.4 → 0.2.5
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.
|
@@ -309,21 +309,37 @@ function getUniqueNodeId(filePath, nodeName, gitHash, usedIds, idCounters) {
|
|
|
309
309
|
return id;
|
|
310
310
|
}
|
|
311
311
|
function isReactComponent(func) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
312
|
+
try {
|
|
313
|
+
let name = "";
|
|
314
|
+
if (typeof func.getName === "function") {
|
|
315
|
+
name = func.getName() || "";
|
|
316
|
+
}
|
|
317
|
+
if (!name && func.getParent) {
|
|
318
|
+
const parent = func.getParent();
|
|
319
|
+
if (parent && typeof parent.asKind === "function") {
|
|
320
|
+
const varDecl = parent.asKind(SyntaxKind.VariableDeclaration);
|
|
321
|
+
if (varDecl && typeof varDecl.getName === "function") {
|
|
322
|
+
name = varDecl.getName() || "";
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
const hasComponentName = name && /^[A-Z]/.test(name);
|
|
327
|
+
const returnType = func.getReturnType()?.getText() || "";
|
|
328
|
+
const hasJsxReturnType = returnType.includes("JSX.Element") || returnType.includes("React.ReactElement") || returnType.includes("ReactElement") || returnType.includes("React.ReactNode") || returnType.includes("ReactNode");
|
|
329
|
+
const body = func.getBody();
|
|
330
|
+
if (!body) return false;
|
|
331
|
+
const hasJsxElements = body.getDescendantsOfKind(SyntaxKind.JsxElement).length > 0 || body.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement).length > 0 || body.getDescendantsOfKind(SyntaxKind.JsxFragment).length > 0;
|
|
332
|
+
const hasHooks = body.getDescendantsOfKind(SyntaxKind.CallExpression).some((call) => {
|
|
333
|
+
const expr = call.getExpression().getText();
|
|
334
|
+
return expr.startsWith("use") && /^use[A-Z]/.test(expr);
|
|
335
|
+
});
|
|
336
|
+
if (hasJsxElements) return true;
|
|
337
|
+
if (hasJsxReturnType) return true;
|
|
338
|
+
if (hasComponentName && hasHooks) return true;
|
|
339
|
+
return false;
|
|
340
|
+
} catch (error) {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
327
343
|
}
|
|
328
344
|
function analyzeReturnStatements(func) {
|
|
329
345
|
const body = func.getBody();
|
package/dist/index.js
CHANGED
package/dist/vite-plugin.js
CHANGED