|
| 1 | +/*! |
| 2 | +
|
| 3 | + diff v5.1.0 |
| 4 | +
|
| 5 | +Software License Agreement (BSD License) |
| 6 | +
|
| 7 | +Copyright (c) 2009-2015, Kevin Decker <kpdecker@gmail.com> |
| 8 | +
|
| 9 | +All rights reserved. |
| 10 | +
|
| 11 | +Redistribution and use of this software in source and binary forms, with or without modification, |
| 12 | +are permitted provided that the following conditions are met: |
| 13 | +
|
| 14 | +* Redistributions of source code must retain the above |
| 15 | + copyright notice, this list of conditions and the |
| 16 | + following disclaimer. |
| 17 | +
|
| 18 | +* Redistributions in binary form must reproduce the above |
| 19 | + copyright notice, this list of conditions and the |
| 20 | + following disclaimer in the documentation and/or other |
| 21 | + materials provided with the distribution. |
| 22 | +
|
| 23 | +* Neither the name of Kevin Decker nor the names of its |
| 24 | + contributors may be used to endorse or promote products |
| 25 | + derived from this software without specific prior |
| 26 | + written permission. |
| 27 | +
|
| 28 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR |
| 29 | +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 30 | +FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 31 | +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 32 | +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 33 | +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 34 | +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 35 | +OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | +@license |
| 37 | +*/ |
1 | 38 | (function (global, factory) {
|
2 | 39 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
3 | 40 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
38 | 75 | oldLen = oldString.length;
|
39 | 76 | var editLength = 1;
|
40 | 77 | var maxEditLength = newLen + oldLen;
|
| 78 | + |
| 79 | + if (options.maxEditLength) { |
| 80 | + maxEditLength = Math.min(maxEditLength, options.maxEditLength); |
| 81 | + } |
| 82 | + |
41 | 83 | var bestPath = [{
|
42 | 84 | newPos: -1,
|
43 | 85 | components: []
|
|
102 | 144 | editLength++;
|
103 | 145 | } // Performs the length of edit iteration. Is a bit fugly as this has to support the
|
104 | 146 | // sync and async mode which is never fun. Loops over execEditLength until a value
|
105 |
| - // is produced. |
| 147 | + // is produced, or until the edit length exceeds options.maxEditLength (if given), |
| 148 | + // in which case it will return undefined. |
106 | 149 |
|
107 | 150 |
|
108 | 151 | if (callback) {
|
109 | 152 | (function exec() {
|
110 | 153 | setTimeout(function () {
|
111 |
| - // This should not happen, but we want to be safe. |
112 |
| - |
113 |
| - /* istanbul ignore next */ |
114 | 154 | if (editLength > maxEditLength) {
|
115 | 155 | return callback();
|
116 | 156 | }
|
|
928 | 968 | }
|
929 | 969 |
|
930 | 970 | var diff = diffLines(oldStr, newStr, options);
|
| 971 | + |
| 972 | + if (!diff) { |
| 973 | + return; |
| 974 | + } |
| 975 | + |
931 | 976 | diff.push({
|
932 | 977 | value: '',
|
933 | 978 | lines: []
|
|
0 commit comments