all files / lib/deps/merge/ traverseRevTree.js

100% Statements 13/13
100% Branches 0/0
100% Functions 1/1
100% Lines 13/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                19401×   19401× 19401× 97183× 97183× 97183× 97183× 97183× 76303×        
"use strict";
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
// Pretty much all below can be combined into a higher order function to
// traverse revisions
// The return value from the callback will be passed as context to all
// children of that node
function traverseRevTree(revs, callback) {
  var toVisit = revs.slice();
 
  var node;
  while (node = toVisit.pop()) {
    var pos = node.pos;
    var tree = node.ids;
    var branches = tree[2];
    var newCtx = callback(branches.length === 0, pos, tree[0], node.ctx, tree[1]);
    for (var i = 0, len = branches.length; i < len; i++) {
      toVisit.push({ pos: pos + 1, ids: branches[i], ctx: newCtx });
    }
  }
}
 
exports.default = traverseRevTree;
module.exports = exports['default'];