devbonzai 1.7.0 → 1.7.1
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/cli.js +41 -11
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -418,12 +418,20 @@ function extractJavaScriptFunctions(filePath) {
|
|
|
418
418
|
return content.substring(node.start, node.end);
|
|
419
419
|
};
|
|
420
420
|
|
|
421
|
+
// Track visited nodes to avoid duplicates
|
|
422
|
+
const visitedNodes = new Set();
|
|
423
|
+
|
|
421
424
|
// Traverse AST
|
|
422
|
-
function traverse(node) {
|
|
425
|
+
function traverse(node, parentType = null) {
|
|
423
426
|
if (!node) return;
|
|
424
427
|
|
|
428
|
+
// Skip if already visited (avoid processing same node twice)
|
|
429
|
+
if (visitedNodes.has(node)) return;
|
|
430
|
+
visitedNodes.add(node);
|
|
431
|
+
|
|
425
432
|
// Function declarations: function myFunc() {}
|
|
426
|
-
if (
|
|
433
|
+
// Skip if inside ExportNamedDeclaration (will be handled below)
|
|
434
|
+
if (node.type === 'FunctionDeclaration' && node.id && parentType !== 'ExportNamedDeclaration') {
|
|
427
435
|
functions.push({
|
|
428
436
|
name: node.id.name,
|
|
429
437
|
content: getCode(node),
|
|
@@ -437,7 +445,6 @@ function extractJavaScriptFunctions(filePath) {
|
|
|
437
445
|
node.init &&
|
|
438
446
|
(node.init.type === 'ArrowFunctionExpression' || node.init.type === 'FunctionExpression') &&
|
|
439
447
|
node.id && node.id.type === 'Identifier') {
|
|
440
|
-
const funcNode = node.init;
|
|
441
448
|
const funcContent = getCode(node);
|
|
442
449
|
functions.push({
|
|
443
450
|
name: node.id.name,
|
|
@@ -448,7 +455,8 @@ function extractJavaScriptFunctions(filePath) {
|
|
|
448
455
|
}
|
|
449
456
|
|
|
450
457
|
// Class declarations: class User { ... }
|
|
451
|
-
if (
|
|
458
|
+
// Skip if inside ExportNamedDeclaration (will be handled below)
|
|
459
|
+
if (node.type === 'ClassDeclaration' && node.id && parentType !== 'ExportNamedDeclaration') {
|
|
452
460
|
const className = node.id.name;
|
|
453
461
|
const methods = [];
|
|
454
462
|
|
|
@@ -491,6 +499,8 @@ function extractJavaScriptFunctions(filePath) {
|
|
|
491
499
|
endLine: node.declaration.loc ? node.declaration.loc.end.line : 0,
|
|
492
500
|
isExported: true
|
|
493
501
|
});
|
|
502
|
+
// Mark as visited to avoid duplicate processing
|
|
503
|
+
visitedNodes.add(node.declaration);
|
|
494
504
|
} else if (node.declaration.type === 'ClassDeclaration' && node.declaration.id) {
|
|
495
505
|
const className = node.declaration.id.name;
|
|
496
506
|
const methods = [];
|
|
@@ -522,6 +532,8 @@ function extractJavaScriptFunctions(filePath) {
|
|
|
522
532
|
endLine: node.declaration.loc ? node.declaration.loc.end.line : 0,
|
|
523
533
|
isExported: true
|
|
524
534
|
});
|
|
535
|
+
// Mark as visited to avoid duplicate processing
|
|
536
|
+
visitedNodes.add(node.declaration);
|
|
525
537
|
}
|
|
526
538
|
}
|
|
527
539
|
|
|
@@ -530,9 +542,9 @@ function extractJavaScriptFunctions(filePath) {
|
|
|
530
542
|
if (key === 'parent' || key === 'leadingComments' || key === 'trailingComments') continue;
|
|
531
543
|
const child = node[key];
|
|
532
544
|
if (Array.isArray(child)) {
|
|
533
|
-
child.forEach(traverse);
|
|
545
|
+
child.forEach(c => traverse(c, node.type));
|
|
534
546
|
} else if (child && typeof child === 'object' && child.type) {
|
|
535
|
-
traverse(child);
|
|
547
|
+
traverse(child, node.type);
|
|
536
548
|
}
|
|
537
549
|
}
|
|
538
550
|
}
|
|
@@ -610,11 +622,20 @@ function extractVueFunctions(filePath) {
|
|
|
610
622
|
return scriptContent.substring(node.start, node.end);
|
|
611
623
|
};
|
|
612
624
|
|
|
625
|
+
// Track visited nodes to avoid duplicates
|
|
626
|
+
const visitedNodes = new Set();
|
|
627
|
+
|
|
613
628
|
// Traverse AST (same logic as JavaScript parser)
|
|
614
|
-
function traverse(node) {
|
|
629
|
+
function traverse(node, parentType = null) {
|
|
615
630
|
if (!node) return;
|
|
616
631
|
|
|
617
|
-
if (
|
|
632
|
+
// Skip if already visited (avoid processing same node twice)
|
|
633
|
+
if (visitedNodes.has(node)) return;
|
|
634
|
+
visitedNodes.add(node);
|
|
635
|
+
|
|
636
|
+
// Function declarations: function myFunc() {}
|
|
637
|
+
// Skip if inside ExportNamedDeclaration (will be handled below)
|
|
638
|
+
if (node.type === 'FunctionDeclaration' && node.id && parentType !== 'ExportNamedDeclaration') {
|
|
618
639
|
functions.push({
|
|
619
640
|
name: node.id.name,
|
|
620
641
|
content: getCode(node),
|
|
@@ -623,6 +644,7 @@ function extractVueFunctions(filePath) {
|
|
|
623
644
|
});
|
|
624
645
|
}
|
|
625
646
|
|
|
647
|
+
// Arrow functions: const myFunc = () => {}
|
|
626
648
|
if (node.type === 'VariableDeclarator' &&
|
|
627
649
|
node.init &&
|
|
628
650
|
(node.init.type === 'ArrowFunctionExpression' || node.init.type === 'FunctionExpression') &&
|
|
@@ -636,7 +658,9 @@ function extractVueFunctions(filePath) {
|
|
|
636
658
|
});
|
|
637
659
|
}
|
|
638
660
|
|
|
639
|
-
|
|
661
|
+
// Class declarations: class User { ... }
|
|
662
|
+
// Skip if inside ExportNamedDeclaration (will be handled below)
|
|
663
|
+
if (node.type === 'ClassDeclaration' && node.id && parentType !== 'ExportNamedDeclaration') {
|
|
640
664
|
const className = node.id.name;
|
|
641
665
|
const methods = [];
|
|
642
666
|
|
|
@@ -668,6 +692,7 @@ function extractVueFunctions(filePath) {
|
|
|
668
692
|
});
|
|
669
693
|
}
|
|
670
694
|
|
|
695
|
+
// Export declarations: export function, export default
|
|
671
696
|
if (node.type === 'ExportNamedDeclaration' && node.declaration) {
|
|
672
697
|
if (node.declaration.type === 'FunctionDeclaration' && node.declaration.id) {
|
|
673
698
|
functions.push({
|
|
@@ -677,6 +702,8 @@ function extractVueFunctions(filePath) {
|
|
|
677
702
|
endLine: node.declaration.loc ? node.declaration.loc.end.line : 0,
|
|
678
703
|
isExported: true
|
|
679
704
|
});
|
|
705
|
+
// Mark as visited to avoid duplicate processing
|
|
706
|
+
visitedNodes.add(node.declaration);
|
|
680
707
|
} else if (node.declaration.type === 'ClassDeclaration' && node.declaration.id) {
|
|
681
708
|
const className = node.declaration.id.name;
|
|
682
709
|
const methods = [];
|
|
@@ -708,16 +735,19 @@ function extractVueFunctions(filePath) {
|
|
|
708
735
|
endLine: node.declaration.loc ? node.declaration.loc.end.line : 0,
|
|
709
736
|
isExported: true
|
|
710
737
|
});
|
|
738
|
+
// Mark as visited to avoid duplicate processing
|
|
739
|
+
visitedNodes.add(node.declaration);
|
|
711
740
|
}
|
|
712
741
|
}
|
|
713
742
|
|
|
743
|
+
// Recursively traverse children
|
|
714
744
|
for (const key in node) {
|
|
715
745
|
if (key === 'parent' || key === 'leadingComments' || key === 'trailingComments') continue;
|
|
716
746
|
const child = node[key];
|
|
717
747
|
if (Array.isArray(child)) {
|
|
718
|
-
child.forEach(traverse);
|
|
748
|
+
child.forEach(c => traverse(c, node.type));
|
|
719
749
|
} else if (child && typeof child === 'object' && child.type) {
|
|
720
|
-
traverse(child);
|
|
750
|
+
traverse(child, node.type);
|
|
721
751
|
}
|
|
722
752
|
}
|
|
723
753
|
}
|