All files / src/matchers has.ts

100% Statements 13/13
75% Branches 3/4
100% Functions 4/4
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26  17x 17x     17x 19x 19x 22x 22x   184x 184x   184x 14x       184x       19x    
// Dependencies:
import { findMatches } from '../match';
import { traverse } from '../traverse';
import { TSQueryNode, TSQuerySelectorNode } from '../tsquery-types';
 
export function has (node: TSQueryNode, selector: TSQuerySelectorNode): boolean {
    const collector: Array<TSQueryNode> = [];
    selector.selectors.forEach(childSelector => {
        const ancestors: Array<TSQueryNode> = [];
        traverse(node, {
            enter (childNode: TSQueryNode, parentNode: TSQueryNode | null): void {
                Eif (parentNode != null) {
                    ancestors.unshift(parentNode);
                }
                if (findMatches(childNode, childSelector, ancestors)) {
                  collector.push(childNode);
                }
            },
            leave (): void {
                ancestors.shift();
            }
        });
    });
    return collector.length > 0;
}