index.js
function compareLocation(nodeA, nodeB) {
  var locA = nodeA && nodeA.loc;
  var locB = nodeB && nodeB.loc;
  if (!locA && !locB) {
    return 0;
  }
  else if (Boolean(locA) !== Boolean(locB)) {
    return locA ? +1 : locB ? -1 : 0;
  }
  else {
    var result =
      isOrdered(locB.end,   locA.start) ? +1 : isOrdered(locA.end,   locB.start) ? -1 : // non-overlapping
      isOrdered(locB.start, locA.start) ? +1 : isOrdered(locA.start, locB.start) ? -1 : // overlapping
      isOrdered(locA.end,   locB.end  ) ? +1 : isOrdered(locB.end,   locA.end  ) ? -1 : // enclosed
      0;
    return result;
  }
}
function compareLocation(nodeA, nodeB) {
  var locA = nodeA && nodeA.loc;
  var locB = nodeB && nodeB.loc;
  if (!locA && !locB) {
    return 0;
  }
  else if (Boolean(locA) !== Boolean(locB)) {
    return locA ? +1 : locB ? -1 : 0;
  }
  else {
    var result =
      isOrdered(locB.end,   locA.start) ? +1 : isOrdered(locA.end,   locB.start) ? -1 : // non-overlapping
      isOrdered(locB.start, locA.start) ? +1 : isOrdered(locA.start, locB.start) ? -1 : // overlapping
      isOrdered(locA.end,   locB.end  ) ? +1 : isOrdered(locB.end,   locA.end  ) ? -1 : // enclosed
      0;
    return result;
  }
}
function compareLocation ( nodeA , nodeB ) { var locA = nodeA && nodeA . loc ; var locB = nodeB && nodeB . loc ; if ( ! locA && ! locB ) { return 0 ; } else if ( Boolean ( locA ) !== Boolean ( locB ) ) { return locA ? + 1 : locB ? - 1 : 0 ; } else { var result = isOrdered ( locB . end , locA . start ) ? + 1 : isOrdered ( locA . end , locB . start ) ? - 1 : // non-overlapping isOrdered ( locB . start , locA . start ) ? + 1 : isOrdered ( locA . start , locB . start ) ? - 1 : // overlapping isOrdered ( locA . end , locB . end ) ? + 1 : isOrdered ( locB . end , locA . end ) ? - 1 : // enclosed 0 ; return result ; } }
Compare function for nodes with location.
@param {object} nodeA First node
@param {object} nodeB Second node
@returns {number} -1 where a follows b, +1 where b follows a, 0 otherwise
Compare function for nodes with location .