Code Duplication    Length = 112-112 lines in 2 locations

node_modules/mocha/mocha.js 1 location

@@ 8669-8780 (lines=112) @@
8666
8667
	/*istanbul ignore start*/function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
8668
8669
	/*istanbul ignore end*/function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
8670
	  if (!options) {
8671
	    options = {};
8672
	  }
8673
	  if (typeof options.context === 'undefined') {
8674
	    options.context = 4;
8675
	  }
8676
8677
	  var diff = /*istanbul ignore start*/(0, _line.diffLines) /*istanbul ignore end*/(oldStr, newStr, options);
8678
	  diff.push({ value: '', lines: [] }); // Append an empty value to make cleanup easier
8679
8680
	  function contextLines(lines) {
8681
	    return lines.map(function (entry) {
8682
	      return ' ' + entry;
8683
	    });
8684
	  }
8685
8686
	  var hunks = [];
8687
	  var oldRangeStart = 0,
8688
	      newRangeStart = 0,
8689
	      curRange = [],
8690
	      oldLine = 1,
8691
	      newLine = 1;
8692
8693
	  /*istanbul ignore start*/var _loop = function _loop( /*istanbul ignore end*/i) {
8694
	    var current = diff[i],
8695
	        lines = current.lines || current.value.replace(/\n$/, '').split('\n');
8696
	    current.lines = lines;
8697
8698
	    if (current.added || current.removed) {
8699
	      /*istanbul ignore start*/var _curRange;
8700
8701
	      /*istanbul ignore end*/ // If we have previous context, start with that
8702
	      if (!oldRangeStart) {
8703
	        var prev = diff[i - 1];
8704
	        oldRangeStart = oldLine;
8705
	        newRangeStart = newLine;
8706
8707
	        if (prev) {
8708
	          curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
8709
	          oldRangeStart -= curRange.length;
8710
	          newRangeStart -= curRange.length;
8711
	        }
8712
	      }
8713
8714
	      // Output our changes
8715
	      /*istanbul ignore start*/(_curRange = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/lines.map(function (entry) {
8716
	        return (current.added ? '+' : '-') + entry;
8717
	      })));
8718
8719
	      // Track the updated file position
8720
	      if (current.added) {
8721
	        newLine += lines.length;
8722
	      } else {
8723
	        oldLine += lines.length;
8724
	      }
8725
	    } else {
8726
	      // Identical context lines. Track line changes
8727
	      if (oldRangeStart) {
8728
	        // Close out any changes that have been output (or join overlapping)
8729
	        if (lines.length <= options.context * 2 && i < diff.length - 2) {
8730
	          /*istanbul ignore start*/var _curRange2;
8731
8732
	          /*istanbul ignore end*/ // Overlapping
8733
	          /*istanbul ignore start*/(_curRange2 = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange2 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/contextLines(lines)));
8734
	        } else {
8735
	          /*istanbul ignore start*/var _curRange3;
8736
8737
	          /*istanbul ignore end*/ // end the range and output
8738
	          var contextSize = Math.min(lines.length, options.context);
8739
	          /*istanbul ignore start*/(_curRange3 = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange3 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/contextLines(lines.slice(0, contextSize))));
8740
8741
	          var hunk = {
8742
	            oldStart: oldRangeStart,
8743
	            oldLines: oldLine - oldRangeStart + contextSize,
8744
	            newStart: newRangeStart,
8745
	            newLines: newLine - newRangeStart + contextSize,
8746
	            lines: curRange
8747
	          };
8748
	          if (i >= diff.length - 2 && lines.length <= options.context) {
8749
	            // EOF is inside this hunk
8750
	            var oldEOFNewline = /\n$/.test(oldStr);
8751
	            var newEOFNewline = /\n$/.test(newStr);
8752
	            if (lines.length == 0 && !oldEOFNewline) {
8753
	              // special case: old has no eol and no trailing context; no-nl can end up before adds
8754
	              curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
8755
	            } else if (!oldEOFNewline || !newEOFNewline) {
8756
	              curRange.push('\\ No newline at end of file');
8757
	            }
8758
	          }
8759
	          hunks.push(hunk);
8760
8761
	          oldRangeStart = 0;
8762
	          newRangeStart = 0;
8763
	          curRange = [];
8764
	        }
8765
	      }
8766
	      oldLine += lines.length;
8767
	      newLine += lines.length;
8768
	    }
8769
	  };
8770
8771
	  for (var i = 0; i < diff.length; i++) {
8772
	    /*istanbul ignore start*/_loop( /*istanbul ignore end*/i);
8773
	  }
8774
8775
	  return {
8776
	    oldFileName: oldFileName, newFileName: newFileName,
8777
	    oldHeader: oldHeader, newHeader: newHeader,
8778
	    hunks: hunks
8779
	  };
8780
	}
8781
8782
	function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
8783
	  var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);

node_modules/diff/lib/patch/create.js 1 location

@@ 12-123 (lines=112) @@
9
10
/*istanbul ignore start*/function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
11
12
/*istanbul ignore end*/function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
13
  if (!options) {
14
    options = {};
15
  }
16
  if (typeof options.context === 'undefined') {
17
    options.context = 4;
18
  }
19
20
  var diff = /*istanbul ignore start*/(0, _line.diffLines) /*istanbul ignore end*/(oldStr, newStr, options);
21
  diff.push({ value: '', lines: [] }); // Append an empty value to make cleanup easier
22
23
  function contextLines(lines) {
24
    return lines.map(function (entry) {
25
      return ' ' + entry;
26
    });
27
  }
28
29
  var hunks = [];
30
  var oldRangeStart = 0,
31
      newRangeStart = 0,
32
      curRange = [],
33
      oldLine = 1,
34
      newLine = 1;
35
36
  /*istanbul ignore start*/var _loop = function _loop( /*istanbul ignore end*/i) {
37
    var current = diff[i],
38
        lines = current.lines || current.value.replace(/\n$/, '').split('\n');
39
    current.lines = lines;
40
41
    if (current.added || current.removed) {
42
      /*istanbul ignore start*/var _curRange;
43
44
      /*istanbul ignore end*/ // If we have previous context, start with that
45
      if (!oldRangeStart) {
46
        var prev = diff[i - 1];
47
        oldRangeStart = oldLine;
48
        newRangeStart = newLine;
49
50
        if (prev) {
51
          curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
52
          oldRangeStart -= curRange.length;
53
          newRangeStart -= curRange.length;
54
        }
55
      }
56
57
      // Output our changes
58
      /*istanbul ignore start*/(_curRange = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/lines.map(function (entry) {
59
        return (current.added ? '+' : '-') + entry;
60
      })));
61
62
      // Track the updated file position
63
      if (current.added) {
64
        newLine += lines.length;
65
      } else {
66
        oldLine += lines.length;
67
      }
68
    } else {
69
      // Identical context lines. Track line changes
70
      if (oldRangeStart) {
71
        // Close out any changes that have been output (or join overlapping)
72
        if (lines.length <= options.context * 2 && i < diff.length - 2) {
73
          /*istanbul ignore start*/var _curRange2;
74
75
          /*istanbul ignore end*/ // Overlapping
76
          /*istanbul ignore start*/(_curRange2 = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange2 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/contextLines(lines)));
77
        } else {
78
          /*istanbul ignore start*/var _curRange3;
79
80
          /*istanbul ignore end*/ // end the range and output
81
          var contextSize = Math.min(lines.length, options.context);
82
          /*istanbul ignore start*/(_curRange3 = /*istanbul ignore end*/curRange).push. /*istanbul ignore start*/apply /*istanbul ignore end*/( /*istanbul ignore start*/_curRange3 /*istanbul ignore end*/, /*istanbul ignore start*/_toConsumableArray( /*istanbul ignore end*/contextLines(lines.slice(0, contextSize))));
83
84
          var hunk = {
85
            oldStart: oldRangeStart,
86
            oldLines: oldLine - oldRangeStart + contextSize,
87
            newStart: newRangeStart,
88
            newLines: newLine - newRangeStart + contextSize,
89
            lines: curRange
90
          };
91
          if (i >= diff.length - 2 && lines.length <= options.context) {
92
            // EOF is inside this hunk
93
            var oldEOFNewline = /\n$/.test(oldStr);
94
            var newEOFNewline = /\n$/.test(newStr);
95
            if (lines.length == 0 && !oldEOFNewline) {
96
              // special case: old has no eol and no trailing context; no-nl can end up before adds
97
              curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
98
            } else if (!oldEOFNewline || !newEOFNewline) {
99
              curRange.push('\\ No newline at end of file');
100
            }
101
          }
102
          hunks.push(hunk);
103
104
          oldRangeStart = 0;
105
          newRangeStart = 0;
106
          curRange = [];
107
        }
108
      }
109
      oldLine += lines.length;
110
      newLine += lines.length;
111
    }
112
  };
113
114
  for (var i = 0; i < diff.length; i++) {
115
    /*istanbul ignore start*/_loop( /*istanbul ignore end*/i);
116
  }
117
118
  return {
119
    oldFileName: oldFileName, newFileName: newFileName,
120
    oldHeader: oldHeader, newHeader: newHeader,
121
    hunks: hunks
122
  };
123
}
124
125
function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
126
  var diff = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);