jspm_packages/npm/babel-core@5.8.38/lib/traversal/path/ancestry.js
function getDeepestCommonAncestorFrom(paths, filter) {
  // istanbul ignore next

  var _this = this;

  if (!paths.length) {
    return this;
  }

  if (paths.length === 1) {
    return paths[0];
  }

  // minimum depth of the tree so we know the highest node
  var minDepth = Infinity;

  // last common ancestor
  var lastCommonIndex, lastCommon;

  // get the ancestors of the path, breaking when the parent exceeds ourselves
  var ancestries = paths.map(function (path) {
    var ancestry = [];

    do {
      ancestry.unshift(path);
    } while ((path = path.parentPath) && path !== _this);

    // save min depth to avoid going too far in
    if (ancestry.length < minDepth) {
      minDepth = ancestry.length;
    }

    return ancestry;
  });

  // get the first ancestry so we have a seed to assess all other ancestries with
  var first = ancestries[0];

  // check ancestor equality
  depthLoop: for (var i = 0; i < minDepth; i++) {
    var shouldMatch = first[i];

    var _arr2 = ancestries;
    for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
      var ancestry = _arr2[_i2];
      if (ancestry[i] !== shouldMatch) {
        // we've hit a snag
        break depthLoop;
      }
    }

    // next iteration may break so store these so they can be returned
    lastCommonIndex = i;
    lastCommon = shouldMatch;
  }

  if (lastCommon) {
    if (filter) {
      return filter(lastCommon, lastCommonIndex, ancestries);
    } else {
      return lastCommon;
    }
  } else {
    throw new Error("Couldn't find intersection");
  }
}
function getDeepestCommonAncestorFrom(paths, filter) {
  // istanbul ignore next

  var _this = this;

  if (!paths.length) {
    return this;
  }

  if (paths.length === 1) {
    return paths[0];
  }

  // minimum depth of the tree so we know the highest node
  var minDepth = Infinity;

  // last common ancestor
  var lastCommonIndex, lastCommon;

  // get the ancestors of the path, breaking when the parent exceeds ourselves
  var ancestries = paths.map(function (path) {
    var ancestry = [];

    do {
      ancestry.unshift(path);
    } while ((path = path.parentPath) && path !== _this);

    // save min depth to avoid going too far in
    if (ancestry.length < minDepth) {
      minDepth = ancestry.length;
    }

    return ancestry;
  });

  // get the first ancestry so we have a seed to assess all other ancestries with
  var first = ancestries[0];

  // check ancestor equality
  depthLoop: for (var i = 0; i < minDepth; i++) {
    var shouldMatch = first[i];

    var _arr2 = ancestries;
    for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
      var ancestry = _arr2[_i2];
      if (ancestry[i] !== shouldMatch) {
        // we've hit a snag
        break depthLoop;
      }
    }

    // next iteration may break so store these so they can be returned
    lastCommonIndex = i;
    lastCommon = shouldMatch;
  }

  if (lastCommon) {
    if (filter) {
      return filter(lastCommon, lastCommonIndex, ancestries);
    } else {
      return lastCommon;
    }
  } else {
    throw new Error("Couldn't find intersection");
  }
}
function getDeepestCommonAncestorFrom ( paths , filter ) { // istanbul ignore next var _this = this ; if ( ! paths . length ) { return this ; } if ( paths . length === 1 ) { return paths [ 0 ] ; } // minimum depth of the tree so we know the highest node var minDepth = Infinity ; // last common ancestor var lastCommonIndex , lastCommon ; // get the ancestors of the path, breaking when the parent exceeds ourselves var ancestries = paths . map ( function ( path ) { var ancestry = [ ] ; do { ancestry . unshift ( path ) ; } while ( ( path = path . parentPath ) && path !== _this ) ; // save min depth to avoid going too far in if ( ancestry . length < minDepth ) { minDepth = ancestry . length ; } return ancestry ; } ) ; // get the first ancestry so we have a seed to assess all other ancestries with var first = ancestries [ 0 ] ; // check ancestor equality depthLoop : for ( var i = 0 ; i < minDepth ; i ++ ) { var shouldMatch = first [ i ] ; var _arr2 = ancestries ; for ( var _i2 = 0 ; _i2 < _arr2 . length ; _i2 ++ ) { var ancestry = _arr2 [ _i2 ] ; if ( ancestry [ i ] !== shouldMatch ) { // we've hit a snag break depthLoop ; } } // next iteration may break so store these so they can be returned lastCommonIndex = i ; lastCommon = shouldMatch ; } if ( lastCommon ) { if ( filter ) { return filter ( lastCommon , lastCommonIndex , ancestries ) ; } else { return lastCommon ; } } else { throw new Error ( "Couldn't find intersection" ) ; } }
Get the earliest path in the tree where the provided `paths` intersect.

TODO: Possible optimisation target.
Get the earliest path in the tree where the provided paths intersect .