Helper function for walkNodeBreadthFirst
189080
function walkNodesBreadthFirstHelper(ast, f) {
  let childAst = [];
  (ast || []).forEach(node => {
    f(node);
    childAst = childAst.concat(getChildren(node));
  });
  if (childAst.length > 0) {
    walkNodesBreadthFirstHelper(childAst, f);
  }
}
640359
function walk(node, callback)
{
	var childNode,i;
	
	if (callback(node) === false) return false;
	
	if (node.childNodes != null)
	{
		i = 0;
		childNode = node.childNodes[i];
	}
	
	while (childNode != null)
	{
		if (walk(childNode, callback) === false) return false;
		
		childNode = node.childNodes[++i];
	}
}
264162
function visit(node, context, visitor) {
	if (node === null || node === undefined) {
		return null;
	}

	if (Array.isArray(visitor)) {
		return visitor
			.reduce((n, v) => {
				const newNode = visit(n, context, v);
				return newNode;
			}, node);
	}

	const method = visitor[node.type];
	if (typeof method === 'function') {
		return method.apply(null, [node].concat(context));
	}

	const defaultMethod = visitor.defaultMethod;
	if (typeof defaultMethod === 'function') {
		return defaultMethod.apply(null, [node].concat(context));
	}

	return node;
}
802189
function walkAll(nodes){
    var result = undefined
    for (var i=0;i<nodes.length;i++){
      var childNode = nodes[i]
      if (childNode.type === 'EmptyStatement') continue
      result = walk(childNode)
      if (result instanceof ReturnValue){
        return result
      }
    }
    return result
  }
1351060
function (callback, ctx) {
            var _walk = function (depth, node, ctx) {
                if (typeof callback === "function")
                    ctx = callback(depth, node, ctx, false);
                var children = node.children();
                for (var i = 0; i < children.length; i++)
                    ctx = _walk(depth + 1, children[i], ctx);
                if (typeof callback === "function")
                    ctx = callback(depth, node, ctx, true);
                return ctx;
            };
            ctx = _walk(0, this, ctx);
            return ctx;
        }
738597
def _iter_walk(
        self,
        fs,  # type: FS
        path,  # type: Text
        namespaces=None,  # type: Optional[Collection[Text]]
    ):
        # type: (...) -> Iterator[Tuple[Text, Optional[Info]]]
        """"""
        if self.search == "breadth":
            return self._walk_breadth(fs, path, namespaces=namespaces)
        else:
            return self._walk_depth(fs, path, namespaces=namespaces)
1283636
private boolean linkFirst(Node<E> node) {
        // assert lock.isHeldByCurrentThread();
        if (count >= capacity)
            return false;
        Node<E> f = first;
        node.next = f;
        first = node;
        if (last == null)
            last = node;
        else
            f.prev = node;
        ++count;
        notEmpty.signal();
        return true;
    }
84449
function walklook(g, iri, walkIri, lookIri, s = new Set(), ws = new Set()) {
  if (ws.has(iri)) return s; // Prevents cycles
  if (!g[iri]) return warn(`Resource missing in graph: ${iri}`) || s;

  ws.add(iri);

  if (g[iri][lookIri]) g[iri][lookIri].forEach(lIri => s.add(lIri));

  if (s.size) return s;

  if (g[iri][walkIri]) g[iri][walkIri].forEach(wIri => walklook(g, wIri, walkIri, lookIri, s, ws));

  return s;
}
49262
function nthMatch(first) {
    return function(node, param) {
      var tmp = param.split(/\s+of\s+/);
      if(tmp.length<2) throw Error("no 'of' keyword in nth-match\"s selector");

      var params = extractNthValue(tmp[0]),
        sl = tmp[1],
        testNode = node.parentNode[first? "firstChild":"lastChild"],
        next = first? "nextSibling" : "previousSibling",
        step = params.step,
        start = params.start,
        position = 0;

        if(!matches(node, sl)) return false;
        if (step === null) return false; //means always false
        do {
          if (testNode.nodeType === 1 && nes.matches(testNode, sl)) position++;
          if (testNode === node) break;
        } while (testNode = testNode[next]);
        
        if (step === 0) return position === start;
        return ((position - start) / step >= 0) && ((position - start) % step === 0);
    };
  }
100699
function walkNodesHelper(astArray, f) {
  (astArray || []).forEach(node => {
    let children = getChildren(node);
    if (children.length > 0) {
      walkNodesHelper(children, f);
    }
    f(node);
  });
}
69177
function cleanUpAST(ast) {
  return walk(ast, function(node, replace) {
    if (node.type === 'Block') {
      var lastIdx = 0;
      var newNodes = [];
      node.nodes.forEach(function(innerNode, i) {
        if (innerNode.type === 'Block' && !innerNode.yield) {
          if (i > 0) newNodes = newNodes.concat(node.nodes.slice(lastIdx, i));
          lastIdx = i + 1;
          newNodes = newNodes.concat(cleanUpAST(innerNode).nodes);
        }
      });
      node.nodes = newNodes.concat(node.nodes.slice(lastIdx));
    }
  });
}
378993
def digraph_walker_backwards(graph, element, call_back):
    """"""
    call_back(graph, element)
    for predecessor in graph.predecessors(element):
        call_back(graph, predecessor)
    for predecessor in graph.predecessors(element):
        digraph_walker_backwards(graph, predecessor, call_back)
328413
function traverseBreadthFirstSync(rootNode, options) {
  options = extend({
    subnodesAccessor: function(node) { return node.subnodes; },
    userdataAccessor: function(node, userdata) { return userdata; },
    onNode: function(node, userdata) {},
    userdata: null
  }, options);

  var queue = [];
  queue.push([rootNode, options.userdata]);

  while (queue.length>0) {
    var front = queue.shift();
    var node = front[0];
    var data = front[1];

    options.onNode(node, data);

    var subnodeData = options.userdataAccessor(node, data);
    var subnodes = options.subnodesAccessor(node);
    for (var i=0; i<subnodes.length; i++) {
      queue.push([subnodes[i], subnodeData]);
    }
  }
  return rootNode;
}
480049
function isFirstNode(node) {
            const parentType = node.parent.type;

            if (node.parent.body) {
                return Array.isArray(node.parent.body)
                    ? node.parent.body[0] === node
                    : node.parent.body === node;
            }

            if (parentType === "IfStatement") {
                return isPrecededByTokens(node, ["else", ")"]);
            }
            if (parentType === "DoWhileStatement") {
                return isPrecededByTokens(node, ["do"]);
            }
            if (parentType === "SwitchCase") {
                return isPrecededByTokens(node, [":"]);
            }
            return isPrecededByTokens(node, [")"]);

        }
462413
function traverseRecursiveSync(rootNode, options) {
  options = extend({
    subnodesAccessor: function(node) { return node.subnodes; },
    onNode: function(node, userdata) {},
    userdata: null
  }, options);

  (function visitNode(node) {
    var subnodes = options.subnodesAccessor(node);
    for (var i=0; i<subnodes.length; i++) {
      visitNode(subnodes[i]);
    }
    options.onNode(node, options.userdata);
  })(rootNode);

  return rootNode;
}
988108
def walk(node):
    
    from collections import deque
    todo = deque([node])
    while todo:
        node = todo.popleft()
        todo.extend(iter_child_nodes(node))
        yield node
901576
function Cursor(tree, start, end) {
        this.tree = tree;
        this.start = start;
        this.end = end;
        
        var self = this;
        this.walk = function walk(node, iterator) {
            if (node === null) return;
            
            if (start !== undefined && node.key < start) {
                walk(node.right, iterator);
            } else if (end !== undefined && node.key > end) {
                walk(node.left, iterator);
            } else {
                walk(node.left, iterator);
                iterator(node.value, node.key, self.tree);
                walk(node.right, iterator);
            }
        };
    }