Traverse into sexp by type and child position
973094
def sfind(sexp, specs)
      specs.inject(sexp) do |node, spec|
        return NotFound if node.nil?

        if spec.is_a?(Symbol) && node.type == spec
          node
        elsif spec.is_a?(Integer) && node.children.length > spec
          node.children[spec]
        elsif spec.is_a?(Array)
          node.children.grep(AST::Node)
            .flat_map { |child| sfind(child, spec) }
            .reject { |child| child == NotFound }
        else
          return NotFound
        end
      end
    end
982678
function(parentNode, reverse, ofType) {
      parentNode._counted = true;
      if (reverse) {
        for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) {
          var node = nodes[i];
          if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++;
        }
      } else {
        for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++)
          if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++;
      }
    }
640972
function traverse(node, callback) {
    callback(node);
    for (var i = 0, cn = node.childNodes, len = cn.length; i < len; i++) {
        var childNode = cn[i];
        if (childNode.tagName) {
            traverse(childNode, callback);
        }
    }
}
878123
function traverse (node, options) {
  if (!node) {
    return ''
  }

  switch (node.type) {
    case 'unary_expr':
    case 'binary_expr':
      return handleExpr(node, options)
    case 'function':
      return handleFunction(node, options)
    case 'expr_list':
      return handleExprList(node, options)
    case 'column_ref':
      return handleColumn(node, options)
    case 'string':
    case 'number':
    case 'null':
    case 'bool':
      return handleValue(node, options)
    case 'timestamp':
      return handleTimestampValue(node, options)
    default:
      throw new Error('Unrecognized AST node: \n' + JSON.stringify(node, null, 2))
  }
}
646725
private static function _getSelectTreeChildren(&$target,$pId,$source,$idField,$pidField,$titleField,$separator,$prefix,$level,$currentLevel)
    {
        if($level<0){
            $level=9999;
        }
        if($currentLevel>$level){
            return;
        }
        $sep="";
        for($i=0;$i<$currentLevel;$i++){
            $sep.=$separator;
        }
        foreach ($source as $item){
            $_pid=$item[$pidField];
            if($_pid==$pId){
                $id=$item[$idField];
                $title=$sep.$prefix.$item[$titleField];
                $target[$id]=$title;
                self::_getSelectTreeChildren($target,$id,$source,$idField,$pidField,$titleField,$separator,$prefix,$level,$currentLevel+1);

            }
        }
    }
216234
function(e, props, targets) {
				var children, i, child, type;
				if (e.slice) {
					i = e.length;
					while (--i > -1) {
						_getChildStyles(e[i], props, targets);
					}
					return;
				}
				children = e.childNodes;
				i = children.length;
				while (--i > -1) {
					child = children[i];
					type = child.type;
					if (child.style) {
						props.push(_getAllStyles(child));
						if (targets) {
							targets.push(child);
						}
					}
					if ((type === 1 || type === 9 || type === 11) && child.childNodes.length) {
						_getChildStyles(child, props, targets);
					}
				}
			}
649564
function getParents (node, test, key, childrenKey, parentKey) {
  var i, v, p = node, path = [];
  while (p) {
    if (test(p)) {
      if (childrenKey) {
        for (i = 0; i < path.length; i++) {
          arrayKV(p, childrenKey, path[i], false, true);
        }
      }
      if (path[0] && parentKey) {
        path[0][parentKey] = p;
      }
      path.unshift(p);
    }
    p = p.parent;
  }
  for (i = 0; i < path.length; i++) {
    v = path[i];
    path[i] = key ? v[key] : v;
  }

  return path
}
889363
def collect_by_type(self, typ):
        '''
        '''
        nodes = []
        if isinstance(self, typ):
            nodes.append(self)
        for c in self:
            nodes.extend(c.collect_by_type(typ))
        return nodes
1308251
function scanChildren(element) {
        var found;
        if (element) {
          for (var i = 0, len = element.length; i < len; i++) {
            var target = element[i];
            if (!found) {
              for (var j = 0, numChild = target.childNodes.length; j < numChild; j++) {
                found = found || scanTree([target.childNodes[j]]);
              }
            }
          }
        }
        return found;
      }
1268525
function getNodesByTypeHelper(childArray, type) {
  let nodes = [].concat(childArray.filter(element => element.type === type));
  let otherNodes = [];
  childArray.forEach(node => {
    if (hasChildren(node)) {
      otherNodes = otherNodes.concat(getNodesByTypeHelper(node.children, type));
    }
  });
  return nodes.concat(otherNodes);
}
821218
def _get_children(self, node):
        """"""
        children = ast.get_children(node)
        return [child for child in children
                if not isinstance(child, ast.expr_context)]
724704
def visit_pass(self, node, parent):
        """"""
        return nodes.Pass(node.lineno, node.col_offset, parent)
933100
private static Tree traverse(Tree parent, List<Tree> kids, Tree node) {
        for (Tree kid : kids) {
            if (kid == node) {
                return parent;
            }

            Tree ret = node.parent(kid);
            if (ret != null) {
                return ret;
            }
        }
        return null;
    }
123745
function(parentNode, reverse, ofType) {
      parentNode._countedByPrototype = Prototype.emptyFunction;
      if (reverse) {
        for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) {
          var node = nodes[i];
          if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;
        }
      } else {
        for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++)
          if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;
      }
    }
156645
function children (options) {
  var context = _children.call(this, options)
  var fn = options.fn
  var inverse = options.inverse
  var i = 0
  var ret = ''
  var data

  var contextPath

  if (options.data) {
    data = handlebars.createFrame(options.data)
  }

  for (var j = context.length; i < j; i++) {
    depthIncrement(options)
    if (data) {
      data.index = i
      data.first = (i === 0)
      data.last = (i === (context.length - 1))

      if (contextPath) {
        data.contextPath = contextPath + i
      }
    }
    ret = ret + fn(context[i], { data: data })
    depthDecrement(options)
  }

  if (i === 0) {
    ret = inverse(this)
  }

  return ret
}
606545
def descendants(self, typename):
        """"""
        xs = []
        for child in self._hier[typename][1]:
            xs.append(child)
            xs.extend(self.descendants(child))
        return xs
263528
def _visit_for(self, cls, node, parent):
        """"""
        newnode = cls(node.lineno, node.col_offset, parent)
        type_annotation = self.check_type_comment(node)
        newnode.postinit(
            target=self.visit(node.target, newnode),
            iter=self.visit(node.iter, newnode),
            body=[self.visit(child, newnode) for child in node.body],
            orelse=[self.visit(child, newnode) for child in node.orelse],
            type_annotation=type_annotation,
        )
        return newnode