Code coverage report for harmonizer/util/insertion.js

Statements: 94.74% (18 / 19)      Branches: 75% (3 / 4)      Functions: 100% (3 / 3)      Lines: 94.74% (18 / 19)      Ignored: none     

All files » harmonizer/util/ » insertion.js
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 27 28 29 30  1 1 1 1 54 54 87 54 54   33     54     54         1 33 33   1 21 21  
'use strict';
var objectPattern = require('nodes');
var objectPatternLists = objectPattern.lists;
var List = objectPatternLists.List;
var listIndex = function (node) {
  var lastNode = node, firstList;
  while (node = node.parentNode) {
    if (node instanceof List) {
      firstList = node;
      break;
    } else {
      lastNode = node;
    }
  }
  Iif (!firstList) {
    throw new Error('parent list not found');
  }
  return {
    list: firstList,
    index: firstList.indexOf(lastNode)
  };
};
exports.insertBefore = function (node, node2) {
  var li = listIndex(node);
  li.list.splice(li.index, 0, node2);
};
exports.insertAfter = function (node, node2) {
  var li = listIndex(node);
  li.list.splice(li.index + 1, 0, node2);
};