File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -57,25 +57,28 @@ export function getSourceNodes(sourceFile: ts.SourceFile): Observable<ts.Node> {
57
57
58
58
59
59
/**
60
- * Find all nodes from the AST in the subtree of node of SyntaxKind kind.
61
- * @param node
62
- * @param kind
63
- * @return all nodes of kind, or [] if none is found
60
+ * Find all nodes from the AST in the subtree of node of SyntaxKind kind.
61
+ * @param node
62
+ * @param kind
63
+ * @param max The maximum number of items to return.
64
+ * @return all nodes of kind, or [] if none is found
64
65
*/
65
66
export function findNodes ( node : ts . Node , kind : ts . SyntaxKind , max : number = Infinity ) : ts . Node [ ] {
66
67
if ( ! node || max == 0 ) {
67
68
return [ ] ;
68
69
}
69
70
70
- let arr : ts . Node [ ] = new Array ( Math . min ( max , 5 ) ) ;
71
+ let arr : ts . Node [ ] = [ ] ;
71
72
if ( node . kind === kind ) {
72
73
arr . push ( node ) ;
73
74
max -- ;
74
75
}
75
76
if ( max > 0 ) {
76
77
for ( const child of node . getChildren ( ) ) {
77
- findNodes ( child , kind ) . forEach ( node => {
78
- arr . push ( node ) ;
78
+ findNodes ( child , kind , max ) . forEach ( node => {
79
+ if ( max > 0 ) {
80
+ arr . push ( node ) ;
81
+ }
79
82
max -- ;
80
83
} ) ;
81
84
You can’t perform that action at this time.
0 commit comments