function findAncestor(ast, predicate) {
    // The visited set protects us against circular references.
    const visited = new Set();
    while (ast.parentNode && !visited.has(ast.parentNode)) {
        if (predicate(ast.parentNode)) {
            return ast.parentNode;
        }
        visited.add(ast.parentNode);
        ast = ast.parentNode;
    }
    return undefined;
}
/**
 * Walk the ancestor nodes from parentNode up to document root, returning the
 * first one matching the predicate function.
 */
Walk the ancestor nodes from parentNode up to document root, returning the
first one matching the predicate function.
Walk the ancestor nodes from parentNode up to document root returning the first one matching the predicate function .
function findAncestor(ast, predicate) {
    const visited = new Set();
    while (ast.parentNode && !visited.has(ast.parentNode)) {
        if (predicate(ast.parentNode)) {
            return ast.parentNode;
        }
        visited.add(ast.parentNode);
        ast = ast.parentNode;
    }
    return undefined;
}
function findAncestor ( ast , predicate ) { const visited = new Set ( ) ; while ( ast . parentNode && ! visited . has ( ast . parentNode ) ) { if ( predicate ( ast . parentNode ) ) { return ast . parentNode ; } visited . add ( ast . parentNode ) ; ast = ast . parentNode ; } return undefined ; }
Walk the ancestor nodes from parentNode up to document root, returning the
 first one matching the predicate function.
Walk the ancestor nodes from parentNode up to document root returning the first one matching the predicate function .
// The visited set protects us against circular references.