(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options)
| 922 | } |
| 923 | |
| 924 | function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) { |
| 925 | if (!options) { |
| 926 | options = {}; |
| 927 | } |
| 928 | |
| 929 | if (typeof options.context === 'undefined') { |
| 930 | options.context = 4; |
| 931 | } |
| 932 | |
| 933 | var diff = diffLines(oldStr, newStr, options); |
| 934 | |
| 935 | if (!diff) { |
| 936 | return; |
| 937 | } |
| 938 | |
| 939 | diff.push({ |
| 940 | value: '', |
| 941 | lines: [] |
| 942 | }); // Append an empty value to make cleanup easier |
| 943 | |
| 944 | function contextLines(lines) { |
| 945 | return lines.map(function (entry) { |
| 946 | return ' ' + entry; |
| 947 | }); |
| 948 | } |
| 949 | |
| 950 | var hunks = []; |
| 951 | var oldRangeStart = 0, |
| 952 | newRangeStart = 0, |
| 953 | curRange = [], |
| 954 | oldLine = 1, |
| 955 | newLine = 1; |
| 956 | |
| 957 | var _loop = function _loop(i) { |
| 958 | var current = diff[i], |
| 959 | lines = current.lines || current.value.replace(/\n$/, '').split('\n'); |
| 960 | current.lines = lines; |
| 961 | |
| 962 | if (current.added || current.removed) { |
| 963 | var _curRange; |
| 964 | |
| 965 | // If we have previous context, start with that |
| 966 | if (!oldRangeStart) { |
| 967 | var prev = diff[i - 1]; |
| 968 | oldRangeStart = oldLine; |
| 969 | newRangeStart = newLine; |
| 970 | |
| 971 | if (prev) { |
| 972 | curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : []; |
| 973 | oldRangeStart -= curRange.length; |
| 974 | newRangeStart -= curRange.length; |
| 975 | } |
| 976 | } // Output our changes |
| 977 | |
| 978 | |
| 979 | (_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) { |
| 980 | return (current.added ? '+' : '-') + entry; |
| 981 | }))); // Track the updated file position |
no test coverage detected