index.js
function breadthFirst(node, parent) {
  var results = [];
  if (node && (typeof node === 'object')) {

    // begin the queue with the given node
    var queue = [{node:node, parent:parent}];
    while (queue.length) {

      // pull the next item from the front of the queue
      var item = queue.shift();
      node   = item.node;
      parent = item.parent;

      // valid node so push it to the list and set new parent
      //  don't overwrite parent if one was not given
      if ('type' in node) {
        if (parent !== undefined) {
          node.parent = parent;
        }
        parent = node;
        results.push(node);
      }

      // recurse object members using the queue
      for (var key in node) {
        if (WHITE_LIST.test(key)) {
          var value = node[key];
          if (value && (typeof value === 'object')) {
            queue.push({
              node  : value,
              parent: parent
            });
          }
        }
      }
    }
  }
  return results;
}
function breadthFirst(node, parent) {
  var results = [];
  if (node && (typeof node === 'object')) {

    // begin the queue with the given node
    var queue = [{node:node, parent:parent}];
    while (queue.length) {

      // pull the next item from the front of the queue
      var item = queue.shift();
      node   = item.node;
      parent = item.parent;

      // valid node so push it to the list and set new parent
      //  don't overwrite parent if one was not given
      if ('type' in node) {
        if (parent !== undefined) {
          node.parent = parent;
        }
        parent = node;
        results.push(node);
      }

      // recurse object members using the queue
      for (var key in node) {
        if (WHITE_LIST.test(key)) {
          var value = node[key];
          if (value && (typeof value === 'object')) {
            queue.push({
              node  : value,
              parent: parent
            });
          }
        }
      }
    }
  }
  return results;
}
function breadthFirst ( node , parent ) { var results = [ ] ; if ( node && ( typeof node === 'object' ) ) { // begin the queue with the given node var queue = [ { node : node , parent : parent } ] ; while ( queue . length ) { // pull the next item from the front of the queue var item = queue . shift ( ) ; node = item . node ; parent = item . parent ; // valid node so push it to the list and set new parent //  don't overwrite parent if one was not given if ( 'type' in node ) { if ( parent !== undefined ) { node . parent = parent ; } parent = node ; results . push ( node ) ; } // recurse object members using the queue for ( var key in node ) { if ( WHITE_LIST . test ( key ) ) { var value = node [ key ] ; if ( value && ( typeof value === 'object' ) ) { queue . push ( { node : value , parent : parent } ) ; } } } } } return results ; }
List the given node and all children, breadth first.
@param {object} node An esprima node
@param {object|undefined} [parent] The parent of the given node, where known
@returns {Array} A list of nodes
List the given node and all children breadth first .