Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function flatten( ast, scope, depth ) {
var out = [];
walk( ast, visit );
return out;
/**
* Callback invoked upon visiting an AST node.
*
* @private
* @param {Node} node - AST node
* @param {*} state - state
* @param {Array} ancestors - ancestor nodes
*/
function visit( node, state, ancestors ) {
var level;
var type;
var d;
var i;
if ( node !== ast && contains( types, node.type ) ) {
function fullAncestor (node, callback, baseVisitor, state) {
return walk.fullAncestor(node, callback, baseVisitor || base, state)
}
function fullAncestor (node, callback, baseVisitor, state) {
return walk.fullAncestor(node, callback, baseVisitor || base, state)
}
const findAncestor = (node) => {
let ancestor = null;
walk.fullAncestor(copy, (test, ancestors) => {
if (node === test) {
ancestor = ancestors[ancestors.length - 2];
}
});
return ancestor;
}
function fullAncestor (node, callback, baseVisitor, state) {
return walk.fullAncestor(node, callback, baseVisitor || base, state)
}
export function walkFullAncestor(node: Ast.Node, callback: AstAncestorVisitorCallback, baseVisitor = base, state?: T): void {
acornWalk.fullAncestor(node, callback, baseVisitor, state);
}