Skip to content

Commit 8c7566f

Browse files
committed
Fix findNodes WRT tests.
1 parent d572792 commit 8c7566f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

addon/ng2/utilities/ast-utils.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,28 @@ export function getSourceNodes(sourceFile: ts.SourceFile): Observable<ts.Node> {
5757

5858

5959
/**
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
6465
*/
6566
export function findNodes(node: ts.Node, kind: ts.SyntaxKind, max: number = Infinity): ts.Node[] {
6667
if (!node || max == 0) {
6768
return [];
6869
}
6970

70-
let arr: ts.Node[] = new Array(Math.min(max, 5));
71+
let arr: ts.Node[] = [];
7172
if (node.kind === kind) {
7273
arr.push(node);
7374
max--;
7475
}
7576
if (max > 0) {
7677
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+
}
7982
max--;
8083
});
8184

0 commit comments

Comments
 (0)