schematics/src/ng-add/utils.js
function findNodes(node, kind, max = Infinity) {
    if (!node || max == 0) {
        return [];
    }
    const arr = [];
    if (node.kind === kind) {
        arr.push(node);
        max--;
    }
    if (max > 0) {
        for (const child of node.getChildren()) {
            findNodes(child, kind, max).forEach(node => {
                if (max > 0) {
                    arr.push(node);
                }
                max--;
            });
            if (max <= 0) {
                break;
            }
        }
    }
    return arr;
}
function findNodes(node, kind, max = Infinity) {
    if (!node || max == 0) {
        return [];
    }
    const arr = [];
    if (node.kind === kind) {
        arr.push(node);
        max--;
    }
    if (max > 0) {
        for (const child of node.getChildren()) {
            findNodes(child, kind, max).forEach(node => {
                if (max > 0) {
                    arr.push(node);
                }
                max--;
            });
            if (max <= 0) {
                break;
            }
        }
    }
    return arr;
}
function findNodes ( node , kind , max = Infinity ) { if ( ! node || max == 0 ) { return [ ] ; } const arr = [ ] ; if ( node . kind === kind ) { arr . push ( node ) ; max -- ; } if ( max > 0 ) { for ( const child of node . getChildren ( ) ) { findNodes ( child , kind , max ) . forEach ( node => { if ( max > 0 ) { arr . push ( node ) ; } max -- ; } ) ; if ( max <= 0 ) { break ; } } } return arr ; }
Find all nodes from the AST in the subtree of node of SyntaxKind kind.
@param node
@param kind
@param max The maximum number of items to return.
@return all nodes of kind, or [] if none is found
Find all nodes from the AST in the subtree of node of SyntaxKind kind .