@vitest/utils 3.1.0-beta.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/diff.js CHANGED
@@ -4,365 +4,428 @@ import { g as getDefaultExportFromCjs, s as stringify } from './chunk-_commonjsH
4
4
  import { deepClone, getOwnProperties, getType as getType$1 } from './helpers.js';
5
5
  import 'loupe';
6
6
 
7
+ /**
8
+ * Diff Match and Patch
9
+ * Copyright 2018 The diff-match-patch Authors.
10
+ * https://github.com/google/diff-match-patch
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+ /**
25
+ * @fileoverview Computes the difference between two texts to create a patch.
26
+ * Applies the patch onto another text, allowing for errors.
27
+ * @author fraser@google.com (Neil Fraser)
28
+ */
29
+ /**
30
+ * CHANGES by pedrottimark to diff_match_patch_uncompressed.ts file:
31
+ *
32
+ * 1. Delete anything not needed to use diff_cleanupSemantic method
33
+ * 2. Convert from prototype properties to var declarations
34
+ * 3. Convert Diff to class from constructor and prototype
35
+ * 4. Add type annotations for arguments and return values
36
+ * 5. Add exports
37
+ */
38
+ /**
39
+ * The data structure representing a diff is an array of tuples:
40
+ * [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']]
41
+ * which means: delete 'Hello', add 'Goodbye' and keep ' world.'
42
+ */
7
43
  const DIFF_DELETE = -1;
8
44
  const DIFF_INSERT = 1;
9
45
  const DIFF_EQUAL = 0;
46
+ /**
47
+ * Class representing one diff tuple.
48
+ * Attempts to look like a two-element array (which is what this used to be).
49
+ * @param {number} op Operation, one of: DIFF_DELETE, DIFF_INSERT, DIFF_EQUAL.
50
+ * @param {string} text Text to be deleted, inserted, or retained.
51
+ * @constructor
52
+ */
10
53
  class Diff {
11
- 0;
12
- 1;
13
- constructor(op, text) {
14
- this[0] = op;
15
- this[1] = text;
16
- }
54
+ 0;
55
+ 1;
56
+ constructor(op, text) {
57
+ this[0] = op;
58
+ this[1] = text;
59
+ }
17
60
  }
61
+ /**
62
+ * Determine the common prefix of two strings.
63
+ * @param {string} text1 First string.
64
+ * @param {string} text2 Second string.
65
+ * @return {number} The number of characters common to the start of each
66
+ * string.
67
+ */
18
68
  function diff_commonPrefix(text1, text2) {
19
- if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0)) {
20
- return 0;
21
- }
22
- let pointermin = 0;
23
- let pointermax = Math.min(text1.length, text2.length);
24
- let pointermid = pointermax;
25
- let pointerstart = 0;
26
- while (pointermin < pointermid) {
27
- if (text1.substring(pointerstart, pointermid) === text2.substring(pointerstart, pointermid)) {
28
- pointermin = pointermid;
29
- pointerstart = pointermin;
30
- } else {
31
- pointermax = pointermid;
32
- }
33
- pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
34
- }
35
- return pointermid;
69
+ if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0)) {
70
+ return 0;
71
+ }
72
+ let pointermin = 0;
73
+ let pointermax = Math.min(text1.length, text2.length);
74
+ let pointermid = pointermax;
75
+ let pointerstart = 0;
76
+ while (pointermin < pointermid) {
77
+ if (text1.substring(pointerstart, pointermid) === text2.substring(pointerstart, pointermid)) {
78
+ pointermin = pointermid;
79
+ pointerstart = pointermin;
80
+ } else {
81
+ pointermax = pointermid;
82
+ }
83
+ pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
84
+ }
85
+ return pointermid;
36
86
  }
87
+ /**
88
+ * Determine the common suffix of two strings.
89
+ * @param {string} text1 First string.
90
+ * @param {string} text2 Second string.
91
+ * @return {number} The number of characters common to the end of each string.
92
+ */
37
93
  function diff_commonSuffix(text1, text2) {
38
- if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1)) {
39
- return 0;
40
- }
41
- let pointermin = 0;
42
- let pointermax = Math.min(text1.length, text2.length);
43
- let pointermid = pointermax;
44
- let pointerend = 0;
45
- while (pointermin < pointermid) {
46
- if (text1.substring(text1.length - pointermid, text1.length - pointerend) === text2.substring(text2.length - pointermid, text2.length - pointerend)) {
47
- pointermin = pointermid;
48
- pointerend = pointermin;
49
- } else {
50
- pointermax = pointermid;
51
- }
52
- pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
53
- }
54
- return pointermid;
94
+ if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1)) {
95
+ return 0;
96
+ }
97
+ let pointermin = 0;
98
+ let pointermax = Math.min(text1.length, text2.length);
99
+ let pointermid = pointermax;
100
+ let pointerend = 0;
101
+ while (pointermin < pointermid) {
102
+ if (text1.substring(text1.length - pointermid, text1.length - pointerend) === text2.substring(text2.length - pointermid, text2.length - pointerend)) {
103
+ pointermin = pointermid;
104
+ pointerend = pointermin;
105
+ } else {
106
+ pointermax = pointermid;
107
+ }
108
+ pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
109
+ }
110
+ return pointermid;
55
111
  }
112
+ /**
113
+ * Determine if the suffix of one string is the prefix of another.
114
+ * @param {string} text1 First string.
115
+ * @param {string} text2 Second string.
116
+ * @return {number} The number of characters common to the end of the first
117
+ * string and the start of the second string.
118
+ * @private
119
+ */
56
120
  function diff_commonOverlap_(text1, text2) {
57
- const text1_length = text1.length;
58
- const text2_length = text2.length;
59
- if (text1_length === 0 || text2_length === 0) {
60
- return 0;
61
- }
62
- if (text1_length > text2_length) {
63
- text1 = text1.substring(text1_length - text2_length);
64
- } else if (text1_length < text2_length) {
65
- text2 = text2.substring(0, text1_length);
66
- }
67
- const text_length = Math.min(text1_length, text2_length);
68
- if (text1 === text2) {
69
- return text_length;
70
- }
71
- let best = 0;
72
- let length = 1;
73
- while (true) {
74
- const pattern = text1.substring(text_length - length);
75
- const found = text2.indexOf(pattern);
76
- if (found === -1) {
77
- return best;
78
- }
79
- length += found;
80
- if (found === 0 || text1.substring(text_length - length) === text2.substring(0, length)) {
81
- best = length;
82
- length++;
83
- }
84
- }
121
+ const text1_length = text1.length;
122
+ const text2_length = text2.length;
123
+ if (text1_length === 0 || text2_length === 0) {
124
+ return 0;
125
+ }
126
+ if (text1_length > text2_length) {
127
+ text1 = text1.substring(text1_length - text2_length);
128
+ } else if (text1_length < text2_length) {
129
+ text2 = text2.substring(0, text1_length);
130
+ }
131
+ const text_length = Math.min(text1_length, text2_length);
132
+ if (text1 === text2) {
133
+ return text_length;
134
+ }
135
+ let best = 0;
136
+ let length = 1;
137
+ while (true) {
138
+ const pattern = text1.substring(text_length - length);
139
+ const found = text2.indexOf(pattern);
140
+ if (found === -1) {
141
+ return best;
142
+ }
143
+ length += found;
144
+ if (found === 0 || text1.substring(text_length - length) === text2.substring(0, length)) {
145
+ best = length;
146
+ length++;
147
+ }
148
+ }
85
149
  }
150
+ /**
151
+ * Reduce the number of edits by eliminating semantically trivial equalities.
152
+ * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
153
+ */
86
154
  function diff_cleanupSemantic(diffs) {
87
- let changes = false;
88
- const equalities = [];
89
- let equalitiesLength = 0;
90
- let lastEquality = null;
91
- let pointer = 0;
92
- let length_insertions1 = 0;
93
- let length_deletions1 = 0;
94
- let length_insertions2 = 0;
95
- let length_deletions2 = 0;
96
- while (pointer < diffs.length) {
97
- if (diffs[pointer][0] === DIFF_EQUAL) {
98
- equalities[equalitiesLength++] = pointer;
99
- length_insertions1 = length_insertions2;
100
- length_deletions1 = length_deletions2;
101
- length_insertions2 = 0;
102
- length_deletions2 = 0;
103
- lastEquality = diffs[pointer][1];
104
- } else {
105
- if (diffs[pointer][0] === DIFF_INSERT) {
106
- length_insertions2 += diffs[pointer][1].length;
107
- } else {
108
- length_deletions2 += diffs[pointer][1].length;
109
- }
110
- if (lastEquality && lastEquality.length <= Math.max(length_insertions1, length_deletions1) && lastEquality.length <= Math.max(length_insertions2, length_deletions2)) {
111
- diffs.splice(
112
- equalities[equalitiesLength - 1],
113
- 0,
114
- new Diff(DIFF_DELETE, lastEquality)
115
- );
116
- diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
117
- equalitiesLength--;
118
- equalitiesLength--;
119
- pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1;
120
- length_insertions1 = 0;
121
- length_deletions1 = 0;
122
- length_insertions2 = 0;
123
- length_deletions2 = 0;
124
- lastEquality = null;
125
- changes = true;
126
- }
127
- }
128
- pointer++;
129
- }
130
- if (changes) {
131
- diff_cleanupMerge(diffs);
132
- }
133
- diff_cleanupSemanticLossless(diffs);
134
- pointer = 1;
135
- while (pointer < diffs.length) {
136
- if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) {
137
- const deletion = diffs[pointer - 1][1];
138
- const insertion = diffs[pointer][1];
139
- const overlap_length1 = diff_commonOverlap_(deletion, insertion);
140
- const overlap_length2 = diff_commonOverlap_(insertion, deletion);
141
- if (overlap_length1 >= overlap_length2) {
142
- if (overlap_length1 >= deletion.length / 2 || overlap_length1 >= insertion.length / 2) {
143
- diffs.splice(
144
- pointer,
145
- 0,
146
- new Diff(DIFF_EQUAL, insertion.substring(0, overlap_length1))
147
- );
148
- diffs[pointer - 1][1] = deletion.substring(
149
- 0,
150
- deletion.length - overlap_length1
151
- );
152
- diffs[pointer + 1][1] = insertion.substring(overlap_length1);
153
- pointer++;
154
- }
155
- } else {
156
- if (overlap_length2 >= deletion.length / 2 || overlap_length2 >= insertion.length / 2) {
157
- diffs.splice(
158
- pointer,
159
- 0,
160
- new Diff(DIFF_EQUAL, deletion.substring(0, overlap_length2))
161
- );
162
- diffs[pointer - 1][0] = DIFF_INSERT;
163
- diffs[pointer - 1][1] = insertion.substring(
164
- 0,
165
- insertion.length - overlap_length2
166
- );
167
- diffs[pointer + 1][0] = DIFF_DELETE;
168
- diffs[pointer + 1][1] = deletion.substring(overlap_length2);
169
- pointer++;
170
- }
171
- }
172
- pointer++;
173
- }
174
- pointer++;
175
- }
155
+ let changes = false;
156
+ const equalities = [];
157
+ let equalitiesLength = 0;
158
+ /** @type {?string} */
159
+ let lastEquality = null;
160
+ let pointer = 0;
161
+ let length_insertions1 = 0;
162
+ let length_deletions1 = 0;
163
+ let length_insertions2 = 0;
164
+ let length_deletions2 = 0;
165
+ while (pointer < diffs.length) {
166
+ if (diffs[pointer][0] === DIFF_EQUAL) {
167
+ equalities[equalitiesLength++] = pointer;
168
+ length_insertions1 = length_insertions2;
169
+ length_deletions1 = length_deletions2;
170
+ length_insertions2 = 0;
171
+ length_deletions2 = 0;
172
+ lastEquality = diffs[pointer][1];
173
+ } else {
174
+ if (diffs[pointer][0] === DIFF_INSERT) {
175
+ length_insertions2 += diffs[pointer][1].length;
176
+ } else {
177
+ length_deletions2 += diffs[pointer][1].length;
178
+ }
179
+ if (lastEquality && lastEquality.length <= Math.max(length_insertions1, length_deletions1) && lastEquality.length <= Math.max(length_insertions2, length_deletions2)) {
180
+ diffs.splice(equalities[equalitiesLength - 1], 0, new Diff(DIFF_DELETE, lastEquality));
181
+ diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
182
+ equalitiesLength--;
183
+ equalitiesLength--;
184
+ pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1;
185
+ length_insertions1 = 0;
186
+ length_deletions1 = 0;
187
+ length_insertions2 = 0;
188
+ length_deletions2 = 0;
189
+ lastEquality = null;
190
+ changes = true;
191
+ }
192
+ }
193
+ pointer++;
194
+ }
195
+ if (changes) {
196
+ diff_cleanupMerge(diffs);
197
+ }
198
+ diff_cleanupSemanticLossless(diffs);
199
+ pointer = 1;
200
+ while (pointer < diffs.length) {
201
+ if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) {
202
+ const deletion = diffs[pointer - 1][1];
203
+ const insertion = diffs[pointer][1];
204
+ const overlap_length1 = diff_commonOverlap_(deletion, insertion);
205
+ const overlap_length2 = diff_commonOverlap_(insertion, deletion);
206
+ if (overlap_length1 >= overlap_length2) {
207
+ if (overlap_length1 >= deletion.length / 2 || overlap_length1 >= insertion.length / 2) {
208
+ diffs.splice(pointer, 0, new Diff(DIFF_EQUAL, insertion.substring(0, overlap_length1)));
209
+ diffs[pointer - 1][1] = deletion.substring(0, deletion.length - overlap_length1);
210
+ diffs[pointer + 1][1] = insertion.substring(overlap_length1);
211
+ pointer++;
212
+ }
213
+ } else {
214
+ if (overlap_length2 >= deletion.length / 2 || overlap_length2 >= insertion.length / 2) {
215
+ diffs.splice(pointer, 0, new Diff(DIFF_EQUAL, deletion.substring(0, overlap_length2)));
216
+ diffs[pointer - 1][0] = DIFF_INSERT;
217
+ diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlap_length2);
218
+ diffs[pointer + 1][0] = DIFF_DELETE;
219
+ diffs[pointer + 1][1] = deletion.substring(overlap_length2);
220
+ pointer++;
221
+ }
222
+ }
223
+ pointer++;
224
+ }
225
+ pointer++;
226
+ }
176
227
  }
177
228
  const nonAlphaNumericRegex_ = /[^a-z0-9]/i;
178
229
  const whitespaceRegex_ = /\s/;
179
230
  const linebreakRegex_ = /[\r\n]/;
180
231
  const blanklineEndRegex_ = /\n\r?\n$/;
181
232
  const blanklineStartRegex_ = /^\r?\n\r?\n/;
233
+ /**
234
+ * Look for single edits surrounded on both sides by equalities
235
+ * which can be shifted sideways to align the edit to a word boundary.
236
+ * e.g: The c<ins>at c</ins>ame. -> The <ins>cat </ins>came.
237
+ * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
238
+ */
182
239
  function diff_cleanupSemanticLossless(diffs) {
183
- let pointer = 1;
184
- while (pointer < diffs.length - 1) {
185
- if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
186
- let equality1 = diffs[pointer - 1][1];
187
- let edit = diffs[pointer][1];
188
- let equality2 = diffs[pointer + 1][1];
189
- const commonOffset = diff_commonSuffix(equality1, edit);
190
- if (commonOffset) {
191
- const commonString = edit.substring(edit.length - commonOffset);
192
- equality1 = equality1.substring(0, equality1.length - commonOffset);
193
- edit = commonString + edit.substring(0, edit.length - commonOffset);
194
- equality2 = commonString + equality2;
195
- }
196
- let bestEquality1 = equality1;
197
- let bestEdit = edit;
198
- let bestEquality2 = equality2;
199
- let bestScore = diff_cleanupSemanticScore_(equality1, edit) + diff_cleanupSemanticScore_(edit, equality2);
200
- while (edit.charAt(0) === equality2.charAt(0)) {
201
- equality1 += edit.charAt(0);
202
- edit = edit.substring(1) + equality2.charAt(0);
203
- equality2 = equality2.substring(1);
204
- const score = diff_cleanupSemanticScore_(equality1, edit) + diff_cleanupSemanticScore_(edit, equality2);
205
- if (score >= bestScore) {
206
- bestScore = score;
207
- bestEquality1 = equality1;
208
- bestEdit = edit;
209
- bestEquality2 = equality2;
210
- }
211
- }
212
- if (diffs[pointer - 1][1] !== bestEquality1) {
213
- if (bestEquality1) {
214
- diffs[pointer - 1][1] = bestEquality1;
215
- } else {
216
- diffs.splice(pointer - 1, 1);
217
- pointer--;
218
- }
219
- diffs[pointer][1] = bestEdit;
220
- if (bestEquality2) {
221
- diffs[pointer + 1][1] = bestEquality2;
222
- } else {
223
- diffs.splice(pointer + 1, 1);
224
- pointer--;
225
- }
226
- }
227
- }
228
- pointer++;
229
- }
240
+ let pointer = 1;
241
+ while (pointer < diffs.length - 1) {
242
+ if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
243
+ let equality1 = diffs[pointer - 1][1];
244
+ let edit = diffs[pointer][1];
245
+ let equality2 = diffs[pointer + 1][1];
246
+ const commonOffset = diff_commonSuffix(equality1, edit);
247
+ if (commonOffset) {
248
+ const commonString = edit.substring(edit.length - commonOffset);
249
+ equality1 = equality1.substring(0, equality1.length - commonOffset);
250
+ edit = commonString + edit.substring(0, edit.length - commonOffset);
251
+ equality2 = commonString + equality2;
252
+ }
253
+ let bestEquality1 = equality1;
254
+ let bestEdit = edit;
255
+ let bestEquality2 = equality2;
256
+ let bestScore = diff_cleanupSemanticScore_(equality1, edit) + diff_cleanupSemanticScore_(edit, equality2);
257
+ while (edit.charAt(0) === equality2.charAt(0)) {
258
+ equality1 += edit.charAt(0);
259
+ edit = edit.substring(1) + equality2.charAt(0);
260
+ equality2 = equality2.substring(1);
261
+ const score = diff_cleanupSemanticScore_(equality1, edit) + diff_cleanupSemanticScore_(edit, equality2);
262
+ if (score >= bestScore) {
263
+ bestScore = score;
264
+ bestEquality1 = equality1;
265
+ bestEdit = edit;
266
+ bestEquality2 = equality2;
267
+ }
268
+ }
269
+ if (diffs[pointer - 1][1] !== bestEquality1) {
270
+ if (bestEquality1) {
271
+ diffs[pointer - 1][1] = bestEquality1;
272
+ } else {
273
+ diffs.splice(pointer - 1, 1);
274
+ pointer--;
275
+ }
276
+ diffs[pointer][1] = bestEdit;
277
+ if (bestEquality2) {
278
+ diffs[pointer + 1][1] = bestEquality2;
279
+ } else {
280
+ diffs.splice(pointer + 1, 1);
281
+ pointer--;
282
+ }
283
+ }
284
+ }
285
+ pointer++;
286
+ }
230
287
  }
288
+ /**
289
+ * Reorder and merge like edit sections. Merge equalities.
290
+ * Any edit section can move as long as it doesn't cross an equality.
291
+ * @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
292
+ */
231
293
  function diff_cleanupMerge(diffs) {
232
- diffs.push(new Diff(DIFF_EQUAL, ""));
233
- let pointer = 0;
234
- let count_delete = 0;
235
- let count_insert = 0;
236
- let text_delete = "";
237
- let text_insert = "";
238
- let commonlength;
239
- while (pointer < diffs.length) {
240
- switch (diffs[pointer][0]) {
241
- case DIFF_INSERT:
242
- count_insert++;
243
- text_insert += diffs[pointer][1];
244
- pointer++;
245
- break;
246
- case DIFF_DELETE:
247
- count_delete++;
248
- text_delete += diffs[pointer][1];
249
- pointer++;
250
- break;
251
- case DIFF_EQUAL:
252
- if (count_delete + count_insert > 1) {
253
- if (count_delete !== 0 && count_insert !== 0) {
254
- commonlength = diff_commonPrefix(text_insert, text_delete);
255
- if (commonlength !== 0) {
256
- if (pointer - count_delete - count_insert > 0 && diffs[pointer - count_delete - count_insert - 1][0] === DIFF_EQUAL) {
257
- diffs[pointer - count_delete - count_insert - 1][1] += text_insert.substring(0, commonlength);
258
- } else {
259
- diffs.splice(
260
- 0,
261
- 0,
262
- new Diff(DIFF_EQUAL, text_insert.substring(0, commonlength))
263
- );
264
- pointer++;
265
- }
266
- text_insert = text_insert.substring(commonlength);
267
- text_delete = text_delete.substring(commonlength);
268
- }
269
- commonlength = diff_commonSuffix(text_insert, text_delete);
270
- if (commonlength !== 0) {
271
- diffs[pointer][1] = text_insert.substring(text_insert.length - commonlength) + diffs[pointer][1];
272
- text_insert = text_insert.substring(
273
- 0,
274
- text_insert.length - commonlength
275
- );
276
- text_delete = text_delete.substring(
277
- 0,
278
- text_delete.length - commonlength
279
- );
280
- }
281
- }
282
- pointer -= count_delete + count_insert;
283
- diffs.splice(pointer, count_delete + count_insert);
284
- if (text_delete.length) {
285
- diffs.splice(pointer, 0, new Diff(DIFF_DELETE, text_delete));
286
- pointer++;
287
- }
288
- if (text_insert.length) {
289
- diffs.splice(pointer, 0, new Diff(DIFF_INSERT, text_insert));
290
- pointer++;
291
- }
292
- pointer++;
293
- } else if (pointer !== 0 && diffs[pointer - 1][0] === DIFF_EQUAL) {
294
- diffs[pointer - 1][1] += diffs[pointer][1];
295
- diffs.splice(pointer, 1);
296
- } else {
297
- pointer++;
298
- }
299
- count_insert = 0;
300
- count_delete = 0;
301
- text_delete = "";
302
- text_insert = "";
303
- break;
304
- }
305
- }
306
- if (diffs[diffs.length - 1][1] === "") {
307
- diffs.pop();
308
- }
309
- let changes = false;
310
- pointer = 1;
311
- while (pointer < diffs.length - 1) {
312
- if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
313
- if (diffs[pointer][1].substring(
314
- diffs[pointer][1].length - diffs[pointer - 1][1].length
315
- ) === diffs[pointer - 1][1]) {
316
- diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(
317
- 0,
318
- diffs[pointer][1].length - diffs[pointer - 1][1].length
319
- );
320
- diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1];
321
- diffs.splice(pointer - 1, 1);
322
- changes = true;
323
- } else if (diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) === diffs[pointer + 1][1]) {
324
- diffs[pointer - 1][1] += diffs[pointer + 1][1];
325
- diffs[pointer][1] = diffs[pointer][1].substring(diffs[pointer + 1][1].length) + diffs[pointer + 1][1];
326
- diffs.splice(pointer + 1, 1);
327
- changes = true;
328
- }
329
- }
330
- pointer++;
331
- }
332
- if (changes) {
333
- diff_cleanupMerge(diffs);
334
- }
294
+ diffs.push(new Diff(DIFF_EQUAL, ""));
295
+ let pointer = 0;
296
+ let count_delete = 0;
297
+ let count_insert = 0;
298
+ let text_delete = "";
299
+ let text_insert = "";
300
+ let commonlength;
301
+ while (pointer < diffs.length) {
302
+ switch (diffs[pointer][0]) {
303
+ case DIFF_INSERT:
304
+ count_insert++;
305
+ text_insert += diffs[pointer][1];
306
+ pointer++;
307
+ break;
308
+ case DIFF_DELETE:
309
+ count_delete++;
310
+ text_delete += diffs[pointer][1];
311
+ pointer++;
312
+ break;
313
+ case DIFF_EQUAL:
314
+ if (count_delete + count_insert > 1) {
315
+ if (count_delete !== 0 && count_insert !== 0) {
316
+ commonlength = diff_commonPrefix(text_insert, text_delete);
317
+ if (commonlength !== 0) {
318
+ if (pointer - count_delete - count_insert > 0 && diffs[pointer - count_delete - count_insert - 1][0] === DIFF_EQUAL) {
319
+ diffs[pointer - count_delete - count_insert - 1][1] += text_insert.substring(0, commonlength);
320
+ } else {
321
+ diffs.splice(0, 0, new Diff(DIFF_EQUAL, text_insert.substring(0, commonlength)));
322
+ pointer++;
323
+ }
324
+ text_insert = text_insert.substring(commonlength);
325
+ text_delete = text_delete.substring(commonlength);
326
+ }
327
+ commonlength = diff_commonSuffix(text_insert, text_delete);
328
+ if (commonlength !== 0) {
329
+ diffs[pointer][1] = text_insert.substring(text_insert.length - commonlength) + diffs[pointer][1];
330
+ text_insert = text_insert.substring(0, text_insert.length - commonlength);
331
+ text_delete = text_delete.substring(0, text_delete.length - commonlength);
332
+ }
333
+ }
334
+ pointer -= count_delete + count_insert;
335
+ diffs.splice(pointer, count_delete + count_insert);
336
+ if (text_delete.length) {
337
+ diffs.splice(pointer, 0, new Diff(DIFF_DELETE, text_delete));
338
+ pointer++;
339
+ }
340
+ if (text_insert.length) {
341
+ diffs.splice(pointer, 0, new Diff(DIFF_INSERT, text_insert));
342
+ pointer++;
343
+ }
344
+ pointer++;
345
+ } else if (pointer !== 0 && diffs[pointer - 1][0] === DIFF_EQUAL) {
346
+ diffs[pointer - 1][1] += diffs[pointer][1];
347
+ diffs.splice(pointer, 1);
348
+ } else {
349
+ pointer++;
350
+ }
351
+ count_insert = 0;
352
+ count_delete = 0;
353
+ text_delete = "";
354
+ text_insert = "";
355
+ break;
356
+ }
357
+ }
358
+ if (diffs[diffs.length - 1][1] === "") {
359
+ diffs.pop();
360
+ }
361
+ let changes = false;
362
+ pointer = 1;
363
+ while (pointer < diffs.length - 1) {
364
+ if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
365
+ if (diffs[pointer][1].substring(diffs[pointer][1].length - diffs[pointer - 1][1].length) === diffs[pointer - 1][1]) {
366
+ diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(0, diffs[pointer][1].length - diffs[pointer - 1][1].length);
367
+ diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1];
368
+ diffs.splice(pointer - 1, 1);
369
+ changes = true;
370
+ } else if (diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) === diffs[pointer + 1][1]) {
371
+ diffs[pointer - 1][1] += diffs[pointer + 1][1];
372
+ diffs[pointer][1] = diffs[pointer][1].substring(diffs[pointer + 1][1].length) + diffs[pointer + 1][1];
373
+ diffs.splice(pointer + 1, 1);
374
+ changes = true;
375
+ }
376
+ }
377
+ pointer++;
378
+ }
379
+ if (changes) {
380
+ diff_cleanupMerge(diffs);
381
+ }
335
382
  }
383
+ /**
384
+ * Given two strings, compute a score representing whether the internal
385
+ * boundary falls on logical boundaries.
386
+ * Scores range from 6 (best) to 0 (worst).
387
+ * Closure, but does not reference any external variables.
388
+ * @param {string} one First string.
389
+ * @param {string} two Second string.
390
+ * @return {number} The score.
391
+ * @private
392
+ */
336
393
  function diff_cleanupSemanticScore_(one, two) {
337
- if (!one || !two) {
338
- return 6;
339
- }
340
- const char1 = one.charAt(one.length - 1);
341
- const char2 = two.charAt(0);
342
- const nonAlphaNumeric1 = char1.match(nonAlphaNumericRegex_);
343
- const nonAlphaNumeric2 = char2.match(nonAlphaNumericRegex_);
344
- const whitespace1 = nonAlphaNumeric1 && char1.match(whitespaceRegex_);
345
- const whitespace2 = nonAlphaNumeric2 && char2.match(whitespaceRegex_);
346
- const lineBreak1 = whitespace1 && char1.match(linebreakRegex_);
347
- const lineBreak2 = whitespace2 && char2.match(linebreakRegex_);
348
- const blankLine1 = lineBreak1 && one.match(blanklineEndRegex_);
349
- const blankLine2 = lineBreak2 && two.match(blanklineStartRegex_);
350
- if (blankLine1 || blankLine2) {
351
- return 5;
352
- } else if (lineBreak1 || lineBreak2) {
353
- return 4;
354
- } else if (nonAlphaNumeric1 && !whitespace1 && whitespace2) {
355
- return 3;
356
- } else if (whitespace1 || whitespace2) {
357
- return 2;
358
- } else if (nonAlphaNumeric1 || nonAlphaNumeric2) {
359
- return 1;
360
- }
361
- return 0;
394
+ if (!one || !two) {
395
+ return 6;
396
+ }
397
+ const char1 = one.charAt(one.length - 1);
398
+ const char2 = two.charAt(0);
399
+ const nonAlphaNumeric1 = char1.match(nonAlphaNumericRegex_);
400
+ const nonAlphaNumeric2 = char2.match(nonAlphaNumericRegex_);
401
+ const whitespace1 = nonAlphaNumeric1 && char1.match(whitespaceRegex_);
402
+ const whitespace2 = nonAlphaNumeric2 && char2.match(whitespaceRegex_);
403
+ const lineBreak1 = whitespace1 && char1.match(linebreakRegex_);
404
+ const lineBreak2 = whitespace2 && char2.match(linebreakRegex_);
405
+ const blankLine1 = lineBreak1 && one.match(blanklineEndRegex_);
406
+ const blankLine2 = lineBreak2 && two.match(blanklineStartRegex_);
407
+ if (blankLine1 || blankLine2) {
408
+ return 5;
409
+ } else if (lineBreak1 || lineBreak2) {
410
+ return 4;
411
+ } else if (nonAlphaNumeric1 && !whitespace1 && whitespace2) {
412
+ return 3;
413
+ } else if (whitespace1 || whitespace2) {
414
+ return 2;
415
+ } else if (nonAlphaNumeric1 || nonAlphaNumeric2) {
416
+ return 1;
417
+ }
418
+ return 0;
362
419
  }
363
420
 
421
+ /**
422
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
423
+ *
424
+ * This source code is licensed under the MIT license found in the
425
+ * LICENSE file in the root directory of this source tree.
426
+ */
364
427
  const NO_DIFF_MESSAGE = "Compared values have no visual difference.";
365
- const SIMILAR_MESSAGE = "Compared values serialize to the same structure.\nPrinting internal object structure without calling `toJSON` instead.";
428
+ const SIMILAR_MESSAGE = "Compared values serialize to the same structure.\n" + "Printing internal object structure without calling `toJSON` instead.";
366
429
 
367
430
  var build = {};
368
431
 
@@ -1175,904 +1238,774 @@ var buildExports = requireBuild();
1175
1238
  var diffSequences = /*@__PURE__*/getDefaultExportFromCjs(buildExports);
1176
1239
 
1177
1240
  function formatTrailingSpaces(line, trailingSpaceFormatter) {
1178
- return line.replace(/\s+$/, (match) => trailingSpaceFormatter(match));
1241
+ return line.replace(/\s+$/, (match) => trailingSpaceFormatter(match));
1179
1242
  }
1180
1243
  function printDiffLine(line, isFirstOrLast, color, indicator, trailingSpaceFormatter, emptyFirstOrLastLinePlaceholder) {
1181
- return line.length !== 0 ? color(
1182
- `${indicator} ${formatTrailingSpaces(line, trailingSpaceFormatter)}`
1183
- ) : indicator !== " " ? color(indicator) : isFirstOrLast && emptyFirstOrLastLinePlaceholder.length !== 0 ? color(`${indicator} ${emptyFirstOrLastLinePlaceholder}`) : "";
1244
+ return line.length !== 0 ? color(`${indicator} ${formatTrailingSpaces(line, trailingSpaceFormatter)}`) : indicator !== " " ? color(indicator) : isFirstOrLast && emptyFirstOrLastLinePlaceholder.length !== 0 ? color(`${indicator} ${emptyFirstOrLastLinePlaceholder}`) : "";
1184
1245
  }
1185
- function printDeleteLine(line, isFirstOrLast, {
1186
- aColor,
1187
- aIndicator,
1188
- changeLineTrailingSpaceColor,
1189
- emptyFirstOrLastLinePlaceholder
1190
- }) {
1191
- return printDiffLine(
1192
- line,
1193
- isFirstOrLast,
1194
- aColor,
1195
- aIndicator,
1196
- changeLineTrailingSpaceColor,
1197
- emptyFirstOrLastLinePlaceholder
1198
- );
1246
+ function printDeleteLine(line, isFirstOrLast, { aColor, aIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder }) {
1247
+ return printDiffLine(line, isFirstOrLast, aColor, aIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder);
1199
1248
  }
1200
- function printInsertLine(line, isFirstOrLast, {
1201
- bColor,
1202
- bIndicator,
1203
- changeLineTrailingSpaceColor,
1204
- emptyFirstOrLastLinePlaceholder
1205
- }) {
1206
- return printDiffLine(
1207
- line,
1208
- isFirstOrLast,
1209
- bColor,
1210
- bIndicator,
1211
- changeLineTrailingSpaceColor,
1212
- emptyFirstOrLastLinePlaceholder
1213
- );
1249
+ function printInsertLine(line, isFirstOrLast, { bColor, bIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder }) {
1250
+ return printDiffLine(line, isFirstOrLast, bColor, bIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder);
1214
1251
  }
1215
- function printCommonLine(line, isFirstOrLast, {
1216
- commonColor,
1217
- commonIndicator,
1218
- commonLineTrailingSpaceColor,
1219
- emptyFirstOrLastLinePlaceholder
1220
- }) {
1221
- return printDiffLine(
1222
- line,
1223
- isFirstOrLast,
1224
- commonColor,
1225
- commonIndicator,
1226
- commonLineTrailingSpaceColor,
1227
- emptyFirstOrLastLinePlaceholder
1228
- );
1252
+ function printCommonLine(line, isFirstOrLast, { commonColor, commonIndicator, commonLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder }) {
1253
+ return printDiffLine(line, isFirstOrLast, commonColor, commonIndicator, commonLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder);
1229
1254
  }
1230
1255
  function createPatchMark(aStart, aEnd, bStart, bEnd, { patchColor }) {
1231
- return patchColor(
1232
- `@@ -${aStart + 1},${aEnd - aStart} +${bStart + 1},${bEnd - bStart} @@`
1233
- );
1256
+ return patchColor(`@@ -${aStart + 1},${aEnd - aStart} +${bStart + 1},${bEnd - bStart} @@`);
1234
1257
  }
1235
1258
  function joinAlignedDiffsNoExpand(diffs, options) {
1236
- const iLength = diffs.length;
1237
- const nContextLines = options.contextLines;
1238
- const nContextLines2 = nContextLines + nContextLines;
1239
- let jLength = iLength;
1240
- let hasExcessAtStartOrEnd = false;
1241
- let nExcessesBetweenChanges = 0;
1242
- let i = 0;
1243
- while (i !== iLength) {
1244
- const iStart = i;
1245
- while (i !== iLength && diffs[i][0] === DIFF_EQUAL) {
1246
- i += 1;
1247
- }
1248
- if (iStart !== i) {
1249
- if (iStart === 0) {
1250
- if (i > nContextLines) {
1251
- jLength -= i - nContextLines;
1252
- hasExcessAtStartOrEnd = true;
1253
- }
1254
- } else if (i === iLength) {
1255
- const n = i - iStart;
1256
- if (n > nContextLines) {
1257
- jLength -= n - nContextLines;
1258
- hasExcessAtStartOrEnd = true;
1259
- }
1260
- } else {
1261
- const n = i - iStart;
1262
- if (n > nContextLines2) {
1263
- jLength -= n - nContextLines2;
1264
- nExcessesBetweenChanges += 1;
1265
- }
1266
- }
1267
- }
1268
- while (i !== iLength && diffs[i][0] !== DIFF_EQUAL) {
1269
- i += 1;
1270
- }
1271
- }
1272
- const hasPatch = nExcessesBetweenChanges !== 0 || hasExcessAtStartOrEnd;
1273
- if (nExcessesBetweenChanges !== 0) {
1274
- jLength += nExcessesBetweenChanges + 1;
1275
- } else if (hasExcessAtStartOrEnd) {
1276
- jLength += 1;
1277
- }
1278
- const jLast = jLength - 1;
1279
- const lines = [];
1280
- let jPatchMark = 0;
1281
- if (hasPatch) {
1282
- lines.push("");
1283
- }
1284
- let aStart = 0;
1285
- let bStart = 0;
1286
- let aEnd = 0;
1287
- let bEnd = 0;
1288
- const pushCommonLine = (line) => {
1289
- const j = lines.length;
1290
- lines.push(printCommonLine(line, j === 0 || j === jLast, options));
1291
- aEnd += 1;
1292
- bEnd += 1;
1293
- };
1294
- const pushDeleteLine = (line) => {
1295
- const j = lines.length;
1296
- lines.push(printDeleteLine(line, j === 0 || j === jLast, options));
1297
- aEnd += 1;
1298
- };
1299
- const pushInsertLine = (line) => {
1300
- const j = lines.length;
1301
- lines.push(printInsertLine(line, j === 0 || j === jLast, options));
1302
- bEnd += 1;
1303
- };
1304
- i = 0;
1305
- while (i !== iLength) {
1306
- let iStart = i;
1307
- while (i !== iLength && diffs[i][0] === DIFF_EQUAL) {
1308
- i += 1;
1309
- }
1310
- if (iStart !== i) {
1311
- if (iStart === 0) {
1312
- if (i > nContextLines) {
1313
- iStart = i - nContextLines;
1314
- aStart = iStart;
1315
- bStart = iStart;
1316
- aEnd = aStart;
1317
- bEnd = bStart;
1318
- }
1319
- for (let iCommon = iStart; iCommon !== i; iCommon += 1) {
1320
- pushCommonLine(diffs[iCommon][1]);
1321
- }
1322
- } else if (i === iLength) {
1323
- const iEnd = i - iStart > nContextLines ? iStart + nContextLines : i;
1324
- for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) {
1325
- pushCommonLine(diffs[iCommon][1]);
1326
- }
1327
- } else {
1328
- const nCommon = i - iStart;
1329
- if (nCommon > nContextLines2) {
1330
- const iEnd = iStart + nContextLines;
1331
- for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) {
1332
- pushCommonLine(diffs[iCommon][1]);
1333
- }
1334
- lines[jPatchMark] = createPatchMark(
1335
- aStart,
1336
- aEnd,
1337
- bStart,
1338
- bEnd,
1339
- options
1340
- );
1341
- jPatchMark = lines.length;
1342
- lines.push("");
1343
- const nOmit = nCommon - nContextLines2;
1344
- aStart = aEnd + nOmit;
1345
- bStart = bEnd + nOmit;
1346
- aEnd = aStart;
1347
- bEnd = bStart;
1348
- for (let iCommon = i - nContextLines; iCommon !== i; iCommon += 1) {
1349
- pushCommonLine(diffs[iCommon][1]);
1350
- }
1351
- } else {
1352
- for (let iCommon = iStart; iCommon !== i; iCommon += 1) {
1353
- pushCommonLine(diffs[iCommon][1]);
1354
- }
1355
- }
1356
- }
1357
- }
1358
- while (i !== iLength && diffs[i][0] === DIFF_DELETE) {
1359
- pushDeleteLine(diffs[i][1]);
1360
- i += 1;
1361
- }
1362
- while (i !== iLength && diffs[i][0] === DIFF_INSERT) {
1363
- pushInsertLine(diffs[i][1]);
1364
- i += 1;
1365
- }
1366
- }
1367
- if (hasPatch) {
1368
- lines[jPatchMark] = createPatchMark(aStart, aEnd, bStart, bEnd, options);
1369
- }
1370
- return lines.join("\n");
1259
+ const iLength = diffs.length;
1260
+ const nContextLines = options.contextLines;
1261
+ const nContextLines2 = nContextLines + nContextLines;
1262
+ let jLength = iLength;
1263
+ let hasExcessAtStartOrEnd = false;
1264
+ let nExcessesBetweenChanges = 0;
1265
+ let i = 0;
1266
+ while (i !== iLength) {
1267
+ const iStart = i;
1268
+ while (i !== iLength && diffs[i][0] === DIFF_EQUAL) {
1269
+ i += 1;
1270
+ }
1271
+ if (iStart !== i) {
1272
+ if (iStart === 0) {
1273
+ if (i > nContextLines) {
1274
+ jLength -= i - nContextLines;
1275
+ hasExcessAtStartOrEnd = true;
1276
+ }
1277
+ } else if (i === iLength) {
1278
+ const n = i - iStart;
1279
+ if (n > nContextLines) {
1280
+ jLength -= n - nContextLines;
1281
+ hasExcessAtStartOrEnd = true;
1282
+ }
1283
+ } else {
1284
+ const n = i - iStart;
1285
+ if (n > nContextLines2) {
1286
+ jLength -= n - nContextLines2;
1287
+ nExcessesBetweenChanges += 1;
1288
+ }
1289
+ }
1290
+ }
1291
+ while (i !== iLength && diffs[i][0] !== DIFF_EQUAL) {
1292
+ i += 1;
1293
+ }
1294
+ }
1295
+ const hasPatch = nExcessesBetweenChanges !== 0 || hasExcessAtStartOrEnd;
1296
+ if (nExcessesBetweenChanges !== 0) {
1297
+ jLength += nExcessesBetweenChanges + 1;
1298
+ } else if (hasExcessAtStartOrEnd) {
1299
+ jLength += 1;
1300
+ }
1301
+ const jLast = jLength - 1;
1302
+ const lines = [];
1303
+ let jPatchMark = 0;
1304
+ if (hasPatch) {
1305
+ lines.push("");
1306
+ }
1307
+ let aStart = 0;
1308
+ let bStart = 0;
1309
+ let aEnd = 0;
1310
+ let bEnd = 0;
1311
+ const pushCommonLine = (line) => {
1312
+ const j = lines.length;
1313
+ lines.push(printCommonLine(line, j === 0 || j === jLast, options));
1314
+ aEnd += 1;
1315
+ bEnd += 1;
1316
+ };
1317
+ const pushDeleteLine = (line) => {
1318
+ const j = lines.length;
1319
+ lines.push(printDeleteLine(line, j === 0 || j === jLast, options));
1320
+ aEnd += 1;
1321
+ };
1322
+ const pushInsertLine = (line) => {
1323
+ const j = lines.length;
1324
+ lines.push(printInsertLine(line, j === 0 || j === jLast, options));
1325
+ bEnd += 1;
1326
+ };
1327
+ i = 0;
1328
+ while (i !== iLength) {
1329
+ let iStart = i;
1330
+ while (i !== iLength && diffs[i][0] === DIFF_EQUAL) {
1331
+ i += 1;
1332
+ }
1333
+ if (iStart !== i) {
1334
+ if (iStart === 0) {
1335
+ if (i > nContextLines) {
1336
+ iStart = i - nContextLines;
1337
+ aStart = iStart;
1338
+ bStart = iStart;
1339
+ aEnd = aStart;
1340
+ bEnd = bStart;
1341
+ }
1342
+ for (let iCommon = iStart; iCommon !== i; iCommon += 1) {
1343
+ pushCommonLine(diffs[iCommon][1]);
1344
+ }
1345
+ } else if (i === iLength) {
1346
+ const iEnd = i - iStart > nContextLines ? iStart + nContextLines : i;
1347
+ for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) {
1348
+ pushCommonLine(diffs[iCommon][1]);
1349
+ }
1350
+ } else {
1351
+ const nCommon = i - iStart;
1352
+ if (nCommon > nContextLines2) {
1353
+ const iEnd = iStart + nContextLines;
1354
+ for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) {
1355
+ pushCommonLine(diffs[iCommon][1]);
1356
+ }
1357
+ lines[jPatchMark] = createPatchMark(aStart, aEnd, bStart, bEnd, options);
1358
+ jPatchMark = lines.length;
1359
+ lines.push("");
1360
+ const nOmit = nCommon - nContextLines2;
1361
+ aStart = aEnd + nOmit;
1362
+ bStart = bEnd + nOmit;
1363
+ aEnd = aStart;
1364
+ bEnd = bStart;
1365
+ for (let iCommon = i - nContextLines; iCommon !== i; iCommon += 1) {
1366
+ pushCommonLine(diffs[iCommon][1]);
1367
+ }
1368
+ } else {
1369
+ for (let iCommon = iStart; iCommon !== i; iCommon += 1) {
1370
+ pushCommonLine(diffs[iCommon][1]);
1371
+ }
1372
+ }
1373
+ }
1374
+ }
1375
+ while (i !== iLength && diffs[i][0] === DIFF_DELETE) {
1376
+ pushDeleteLine(diffs[i][1]);
1377
+ i += 1;
1378
+ }
1379
+ while (i !== iLength && diffs[i][0] === DIFF_INSERT) {
1380
+ pushInsertLine(diffs[i][1]);
1381
+ i += 1;
1382
+ }
1383
+ }
1384
+ if (hasPatch) {
1385
+ lines[jPatchMark] = createPatchMark(aStart, aEnd, bStart, bEnd, options);
1386
+ }
1387
+ return lines.join("\n");
1371
1388
  }
1372
1389
  function joinAlignedDiffsExpand(diffs, options) {
1373
- return diffs.map((diff, i, diffs2) => {
1374
- const line = diff[1];
1375
- const isFirstOrLast = i === 0 || i === diffs2.length - 1;
1376
- switch (diff[0]) {
1377
- case DIFF_DELETE:
1378
- return printDeleteLine(line, isFirstOrLast, options);
1379
- case DIFF_INSERT:
1380
- return printInsertLine(line, isFirstOrLast, options);
1381
- default:
1382
- return printCommonLine(line, isFirstOrLast, options);
1383
- }
1384
- }).join("\n");
1390
+ return diffs.map((diff, i, diffs) => {
1391
+ const line = diff[1];
1392
+ const isFirstOrLast = i === 0 || i === diffs.length - 1;
1393
+ switch (diff[0]) {
1394
+ case DIFF_DELETE: return printDeleteLine(line, isFirstOrLast, options);
1395
+ case DIFF_INSERT: return printInsertLine(line, isFirstOrLast, options);
1396
+ default: return printCommonLine(line, isFirstOrLast, options);
1397
+ }
1398
+ }).join("\n");
1385
1399
  }
1386
1400
 
1387
1401
  const noColor = (string) => string;
1388
1402
  const DIFF_CONTEXT_DEFAULT = 5;
1389
1403
  const DIFF_TRUNCATE_THRESHOLD_DEFAULT = 0;
1390
1404
  function getDefaultOptions() {
1391
- return {
1392
- aAnnotation: "Expected",
1393
- aColor: c.green,
1394
- aIndicator: "-",
1395
- bAnnotation: "Received",
1396
- bColor: c.red,
1397
- bIndicator: "+",
1398
- changeColor: c.inverse,
1399
- changeLineTrailingSpaceColor: noColor,
1400
- commonColor: c.dim,
1401
- commonIndicator: " ",
1402
- commonLineTrailingSpaceColor: noColor,
1403
- compareKeys: void 0,
1404
- contextLines: DIFF_CONTEXT_DEFAULT,
1405
- emptyFirstOrLastLinePlaceholder: "",
1406
- expand: true,
1407
- includeChangeCounts: false,
1408
- omitAnnotationLines: false,
1409
- patchColor: c.yellow,
1410
- printBasicPrototype: false,
1411
- truncateThreshold: DIFF_TRUNCATE_THRESHOLD_DEFAULT,
1412
- truncateAnnotation: "... Diff result is truncated",
1413
- truncateAnnotationColor: noColor
1414
- };
1405
+ return {
1406
+ aAnnotation: "Expected",
1407
+ aColor: c.green,
1408
+ aIndicator: "-",
1409
+ bAnnotation: "Received",
1410
+ bColor: c.red,
1411
+ bIndicator: "+",
1412
+ changeColor: c.inverse,
1413
+ changeLineTrailingSpaceColor: noColor,
1414
+ commonColor: c.dim,
1415
+ commonIndicator: " ",
1416
+ commonLineTrailingSpaceColor: noColor,
1417
+ compareKeys: undefined,
1418
+ contextLines: DIFF_CONTEXT_DEFAULT,
1419
+ emptyFirstOrLastLinePlaceholder: "",
1420
+ expand: false,
1421
+ includeChangeCounts: false,
1422
+ omitAnnotationLines: false,
1423
+ patchColor: c.yellow,
1424
+ printBasicPrototype: false,
1425
+ truncateThreshold: DIFF_TRUNCATE_THRESHOLD_DEFAULT,
1426
+ truncateAnnotation: "... Diff result is truncated",
1427
+ truncateAnnotationColor: noColor
1428
+ };
1415
1429
  }
1416
1430
  function getCompareKeys(compareKeys) {
1417
- return compareKeys && typeof compareKeys === "function" ? compareKeys : void 0;
1431
+ return compareKeys && typeof compareKeys === "function" ? compareKeys : undefined;
1418
1432
  }
1419
1433
  function getContextLines(contextLines) {
1420
- return typeof contextLines === "number" && Number.isSafeInteger(contextLines) && contextLines >= 0 ? contextLines : DIFF_CONTEXT_DEFAULT;
1434
+ return typeof contextLines === "number" && Number.isSafeInteger(contextLines) && contextLines >= 0 ? contextLines : DIFF_CONTEXT_DEFAULT;
1421
1435
  }
1422
1436
  function normalizeDiffOptions(options = {}) {
1423
- return {
1424
- ...getDefaultOptions(),
1425
- ...options,
1426
- compareKeys: getCompareKeys(options.compareKeys),
1427
- contextLines: getContextLines(options.contextLines)
1428
- };
1437
+ return {
1438
+ ...getDefaultOptions(),
1439
+ ...options,
1440
+ compareKeys: getCompareKeys(options.compareKeys),
1441
+ contextLines: getContextLines(options.contextLines)
1442
+ };
1429
1443
  }
1430
1444
 
1431
1445
  function isEmptyString(lines) {
1432
- return lines.length === 1 && lines[0].length === 0;
1446
+ return lines.length === 1 && lines[0].length === 0;
1433
1447
  }
1434
1448
  function countChanges(diffs) {
1435
- let a = 0;
1436
- let b = 0;
1437
- diffs.forEach((diff) => {
1438
- switch (diff[0]) {
1439
- case DIFF_DELETE:
1440
- a += 1;
1441
- break;
1442
- case DIFF_INSERT:
1443
- b += 1;
1444
- break;
1445
- }
1446
- });
1447
- return { a, b };
1449
+ let a = 0;
1450
+ let b = 0;
1451
+ diffs.forEach((diff) => {
1452
+ switch (diff[0]) {
1453
+ case DIFF_DELETE:
1454
+ a += 1;
1455
+ break;
1456
+ case DIFF_INSERT:
1457
+ b += 1;
1458
+ break;
1459
+ }
1460
+ });
1461
+ return {
1462
+ a,
1463
+ b
1464
+ };
1448
1465
  }
1449
- function printAnnotation({
1450
- aAnnotation,
1451
- aColor,
1452
- aIndicator,
1453
- bAnnotation,
1454
- bColor,
1455
- bIndicator,
1456
- includeChangeCounts,
1457
- omitAnnotationLines
1458
- }, changeCounts) {
1459
- if (omitAnnotationLines) {
1460
- return "";
1461
- }
1462
- let aRest = "";
1463
- let bRest = "";
1464
- if (includeChangeCounts) {
1465
- const aCount = String(changeCounts.a);
1466
- const bCount = String(changeCounts.b);
1467
- const baAnnotationLengthDiff = bAnnotation.length - aAnnotation.length;
1468
- const aAnnotationPadding = " ".repeat(Math.max(0, baAnnotationLengthDiff));
1469
- const bAnnotationPadding = " ".repeat(Math.max(0, -baAnnotationLengthDiff));
1470
- const baCountLengthDiff = bCount.length - aCount.length;
1471
- const aCountPadding = " ".repeat(Math.max(0, baCountLengthDiff));
1472
- const bCountPadding = " ".repeat(Math.max(0, -baCountLengthDiff));
1473
- aRest = `${aAnnotationPadding} ${aIndicator} ${aCountPadding}${aCount}`;
1474
- bRest = `${bAnnotationPadding} ${bIndicator} ${bCountPadding}${bCount}`;
1475
- }
1476
- const a = `${aIndicator} ${aAnnotation}${aRest}`;
1477
- const b = `${bIndicator} ${bAnnotation}${bRest}`;
1478
- return `${aColor(a)}
1479
- ${bColor(b)}
1480
-
1481
- `;
1466
+ function printAnnotation({ aAnnotation, aColor, aIndicator, bAnnotation, bColor, bIndicator, includeChangeCounts, omitAnnotationLines }, changeCounts) {
1467
+ if (omitAnnotationLines) {
1468
+ return "";
1469
+ }
1470
+ let aRest = "";
1471
+ let bRest = "";
1472
+ if (includeChangeCounts) {
1473
+ const aCount = String(changeCounts.a);
1474
+ const bCount = String(changeCounts.b);
1475
+ const baAnnotationLengthDiff = bAnnotation.length - aAnnotation.length;
1476
+ const aAnnotationPadding = " ".repeat(Math.max(0, baAnnotationLengthDiff));
1477
+ const bAnnotationPadding = " ".repeat(Math.max(0, -baAnnotationLengthDiff));
1478
+ const baCountLengthDiff = bCount.length - aCount.length;
1479
+ const aCountPadding = " ".repeat(Math.max(0, baCountLengthDiff));
1480
+ const bCountPadding = " ".repeat(Math.max(0, -baCountLengthDiff));
1481
+ aRest = `${aAnnotationPadding} ${aIndicator} ${aCountPadding}${aCount}`;
1482
+ bRest = `${bAnnotationPadding} ${bIndicator} ${bCountPadding}${bCount}`;
1483
+ }
1484
+ const a = `${aIndicator} ${aAnnotation}${aRest}`;
1485
+ const b = `${bIndicator} ${bAnnotation}${bRest}`;
1486
+ return `${aColor(a)}\n${bColor(b)}\n\n`;
1482
1487
  }
1483
1488
  function printDiffLines(diffs, truncated, options) {
1484
- return printAnnotation(options, countChanges(diffs)) + (options.expand ? joinAlignedDiffsExpand(diffs, options) : joinAlignedDiffsNoExpand(diffs, options)) + (truncated ? options.truncateAnnotationColor(`
1485
- ${options.truncateAnnotation}`) : "");
1489
+ return printAnnotation(options, countChanges(diffs)) + (options.expand ? joinAlignedDiffsExpand(diffs, options) : joinAlignedDiffsNoExpand(diffs, options)) + (truncated ? options.truncateAnnotationColor(`\n${options.truncateAnnotation}`) : "");
1486
1490
  }
1487
1491
  function diffLinesUnified(aLines, bLines, options) {
1488
- const normalizedOptions = normalizeDiffOptions(options);
1489
- const [diffs, truncated] = diffLinesRaw(
1490
- isEmptyString(aLines) ? [] : aLines,
1491
- isEmptyString(bLines) ? [] : bLines,
1492
- normalizedOptions
1493
- );
1494
- return printDiffLines(diffs, truncated, normalizedOptions);
1492
+ const normalizedOptions = normalizeDiffOptions(options);
1493
+ const [diffs, truncated] = diffLinesRaw(isEmptyString(aLines) ? [] : aLines, isEmptyString(bLines) ? [] : bLines, normalizedOptions);
1494
+ return printDiffLines(diffs, truncated, normalizedOptions);
1495
1495
  }
1496
1496
  function diffLinesUnified2(aLinesDisplay, bLinesDisplay, aLinesCompare, bLinesCompare, options) {
1497
- if (isEmptyString(aLinesDisplay) && isEmptyString(aLinesCompare)) {
1498
- aLinesDisplay = [];
1499
- aLinesCompare = [];
1500
- }
1501
- if (isEmptyString(bLinesDisplay) && isEmptyString(bLinesCompare)) {
1502
- bLinesDisplay = [];
1503
- bLinesCompare = [];
1504
- }
1505
- if (aLinesDisplay.length !== aLinesCompare.length || bLinesDisplay.length !== bLinesCompare.length) {
1506
- return diffLinesUnified(aLinesDisplay, bLinesDisplay, options);
1507
- }
1508
- const [diffs, truncated] = diffLinesRaw(
1509
- aLinesCompare,
1510
- bLinesCompare,
1511
- options
1512
- );
1513
- let aIndex = 0;
1514
- let bIndex = 0;
1515
- diffs.forEach((diff) => {
1516
- switch (diff[0]) {
1517
- case DIFF_DELETE:
1518
- diff[1] = aLinesDisplay[aIndex];
1519
- aIndex += 1;
1520
- break;
1521
- case DIFF_INSERT:
1522
- diff[1] = bLinesDisplay[bIndex];
1523
- bIndex += 1;
1524
- break;
1525
- default:
1526
- diff[1] = bLinesDisplay[bIndex];
1527
- aIndex += 1;
1528
- bIndex += 1;
1529
- }
1530
- });
1531
- return printDiffLines(diffs, truncated, normalizeDiffOptions(options));
1497
+ if (isEmptyString(aLinesDisplay) && isEmptyString(aLinesCompare)) {
1498
+ aLinesDisplay = [];
1499
+ aLinesCompare = [];
1500
+ }
1501
+ if (isEmptyString(bLinesDisplay) && isEmptyString(bLinesCompare)) {
1502
+ bLinesDisplay = [];
1503
+ bLinesCompare = [];
1504
+ }
1505
+ if (aLinesDisplay.length !== aLinesCompare.length || bLinesDisplay.length !== bLinesCompare.length) {
1506
+ return diffLinesUnified(aLinesDisplay, bLinesDisplay, options);
1507
+ }
1508
+ const [diffs, truncated] = diffLinesRaw(aLinesCompare, bLinesCompare, options);
1509
+ let aIndex = 0;
1510
+ let bIndex = 0;
1511
+ diffs.forEach((diff) => {
1512
+ switch (diff[0]) {
1513
+ case DIFF_DELETE:
1514
+ diff[1] = aLinesDisplay[aIndex];
1515
+ aIndex += 1;
1516
+ break;
1517
+ case DIFF_INSERT:
1518
+ diff[1] = bLinesDisplay[bIndex];
1519
+ bIndex += 1;
1520
+ break;
1521
+ default:
1522
+ diff[1] = bLinesDisplay[bIndex];
1523
+ aIndex += 1;
1524
+ bIndex += 1;
1525
+ }
1526
+ });
1527
+ return printDiffLines(diffs, truncated, normalizeDiffOptions(options));
1532
1528
  }
1533
1529
  function diffLinesRaw(aLines, bLines, options) {
1534
- const truncate = (options == null ? void 0 : options.truncateThreshold) ?? false;
1535
- const truncateThreshold = Math.max(
1536
- Math.floor((options == null ? void 0 : options.truncateThreshold) ?? 0),
1537
- 0
1538
- );
1539
- const aLength = truncate ? Math.min(aLines.length, truncateThreshold) : aLines.length;
1540
- const bLength = truncate ? Math.min(bLines.length, truncateThreshold) : bLines.length;
1541
- const truncated = aLength !== aLines.length || bLength !== bLines.length;
1542
- const isCommon = (aIndex2, bIndex2) => aLines[aIndex2] === bLines[bIndex2];
1543
- const diffs = [];
1544
- let aIndex = 0;
1545
- let bIndex = 0;
1546
- const foundSubsequence = (nCommon, aCommon, bCommon) => {
1547
- for (; aIndex !== aCommon; aIndex += 1) {
1548
- diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
1549
- }
1550
- for (; bIndex !== bCommon; bIndex += 1) {
1551
- diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
1552
- }
1553
- for (; nCommon !== 0; nCommon -= 1, aIndex += 1, bIndex += 1) {
1554
- diffs.push(new Diff(DIFF_EQUAL, bLines[bIndex]));
1555
- }
1556
- };
1557
- diffSequences(aLength, bLength, isCommon, foundSubsequence);
1558
- for (; aIndex !== aLength; aIndex += 1) {
1559
- diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
1560
- }
1561
- for (; bIndex !== bLength; bIndex += 1) {
1562
- diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
1563
- }
1564
- return [diffs, truncated];
1530
+ const truncate = (options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? false;
1531
+ const truncateThreshold = Math.max(Math.floor((options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? 0), 0);
1532
+ const aLength = truncate ? Math.min(aLines.length, truncateThreshold) : aLines.length;
1533
+ const bLength = truncate ? Math.min(bLines.length, truncateThreshold) : bLines.length;
1534
+ const truncated = aLength !== aLines.length || bLength !== bLines.length;
1535
+ const isCommon = (aIndex, bIndex) => aLines[aIndex] === bLines[bIndex];
1536
+ const diffs = [];
1537
+ let aIndex = 0;
1538
+ let bIndex = 0;
1539
+ const foundSubsequence = (nCommon, aCommon, bCommon) => {
1540
+ for (; aIndex !== aCommon; aIndex += 1) {
1541
+ diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
1542
+ }
1543
+ for (; bIndex !== bCommon; bIndex += 1) {
1544
+ diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
1545
+ }
1546
+ for (; nCommon !== 0; nCommon -= 1, aIndex += 1, bIndex += 1) {
1547
+ diffs.push(new Diff(DIFF_EQUAL, bLines[bIndex]));
1548
+ }
1549
+ };
1550
+ diffSequences(aLength, bLength, isCommon, foundSubsequence);
1551
+ for (; aIndex !== aLength; aIndex += 1) {
1552
+ diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
1553
+ }
1554
+ for (; bIndex !== bLength; bIndex += 1) {
1555
+ diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
1556
+ }
1557
+ return [diffs, truncated];
1565
1558
  }
1566
1559
 
1567
1560
  function getType(value) {
1568
- if (value === void 0) {
1569
- return "undefined";
1570
- } else if (value === null) {
1571
- return "null";
1572
- } else if (Array.isArray(value)) {
1573
- return "array";
1574
- } else if (typeof value === "boolean") {
1575
- return "boolean";
1576
- } else if (typeof value === "function") {
1577
- return "function";
1578
- } else if (typeof value === "number") {
1579
- return "number";
1580
- } else if (typeof value === "string") {
1581
- return "string";
1582
- } else if (typeof value === "bigint") {
1583
- return "bigint";
1584
- } else if (typeof value === "object") {
1585
- if (value != null) {
1586
- if (value.constructor === RegExp) {
1587
- return "regexp";
1588
- } else if (value.constructor === Map) {
1589
- return "map";
1590
- } else if (value.constructor === Set) {
1591
- return "set";
1592
- } else if (value.constructor === Date) {
1593
- return "date";
1594
- }
1595
- }
1596
- return "object";
1597
- } else if (typeof value === "symbol") {
1598
- return "symbol";
1599
- }
1600
- throw new Error(`value of unknown type: ${value}`);
1561
+ if (value === undefined) {
1562
+ return "undefined";
1563
+ } else if (value === null) {
1564
+ return "null";
1565
+ } else if (Array.isArray(value)) {
1566
+ return "array";
1567
+ } else if (typeof value === "boolean") {
1568
+ return "boolean";
1569
+ } else if (typeof value === "function") {
1570
+ return "function";
1571
+ } else if (typeof value === "number") {
1572
+ return "number";
1573
+ } else if (typeof value === "string") {
1574
+ return "string";
1575
+ } else if (typeof value === "bigint") {
1576
+ return "bigint";
1577
+ } else if (typeof value === "object") {
1578
+ if (value != null) {
1579
+ if (value.constructor === RegExp) {
1580
+ return "regexp";
1581
+ } else if (value.constructor === Map) {
1582
+ return "map";
1583
+ } else if (value.constructor === Set) {
1584
+ return "set";
1585
+ } else if (value.constructor === Date) {
1586
+ return "date";
1587
+ }
1588
+ }
1589
+ return "object";
1590
+ } else if (typeof value === "symbol") {
1591
+ return "symbol";
1592
+ }
1593
+ throw new Error(`value of unknown type: ${value}`);
1601
1594
  }
1602
1595
 
1603
1596
  function getNewLineSymbol(string) {
1604
- return string.includes("\r\n") ? "\r\n" : "\n";
1597
+ return string.includes("\r\n") ? "\r\n" : "\n";
1605
1598
  }
1606
1599
  function diffStrings(a, b, options) {
1607
- const truncate = (options == null ? void 0 : options.truncateThreshold) ?? false;
1608
- const truncateThreshold = Math.max(
1609
- Math.floor((options == null ? void 0 : options.truncateThreshold) ?? 0),
1610
- 0
1611
- );
1612
- let aLength = a.length;
1613
- let bLength = b.length;
1614
- if (truncate) {
1615
- const aMultipleLines = a.includes("\n");
1616
- const bMultipleLines = b.includes("\n");
1617
- const aNewLineSymbol = getNewLineSymbol(a);
1618
- const bNewLineSymbol = getNewLineSymbol(b);
1619
- const _a = aMultipleLines ? `${a.split(aNewLineSymbol, truncateThreshold).join(aNewLineSymbol)}
1620
- ` : a;
1621
- const _b = bMultipleLines ? `${b.split(bNewLineSymbol, truncateThreshold).join(bNewLineSymbol)}
1622
- ` : b;
1623
- aLength = _a.length;
1624
- bLength = _b.length;
1625
- }
1626
- const truncated = aLength !== a.length || bLength !== b.length;
1627
- const isCommon = (aIndex2, bIndex2) => a[aIndex2] === b[bIndex2];
1628
- let aIndex = 0;
1629
- let bIndex = 0;
1630
- const diffs = [];
1631
- const foundSubsequence = (nCommon, aCommon, bCommon) => {
1632
- if (aIndex !== aCommon) {
1633
- diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex, aCommon)));
1634
- }
1635
- if (bIndex !== bCommon) {
1636
- diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex, bCommon)));
1637
- }
1638
- aIndex = aCommon + nCommon;
1639
- bIndex = bCommon + nCommon;
1640
- diffs.push(new Diff(DIFF_EQUAL, b.slice(bCommon, bIndex)));
1641
- };
1642
- diffSequences(aLength, bLength, isCommon, foundSubsequence);
1643
- if (aIndex !== aLength) {
1644
- diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex)));
1645
- }
1646
- if (bIndex !== bLength) {
1647
- diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex)));
1648
- }
1649
- return [diffs, truncated];
1600
+ const truncate = (options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? false;
1601
+ const truncateThreshold = Math.max(Math.floor((options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? 0), 0);
1602
+ let aLength = a.length;
1603
+ let bLength = b.length;
1604
+ if (truncate) {
1605
+ const aMultipleLines = a.includes("\n");
1606
+ const bMultipleLines = b.includes("\n");
1607
+ const aNewLineSymbol = getNewLineSymbol(a);
1608
+ const bNewLineSymbol = getNewLineSymbol(b);
1609
+ const _a = aMultipleLines ? `${a.split(aNewLineSymbol, truncateThreshold).join(aNewLineSymbol)}\n` : a;
1610
+ const _b = bMultipleLines ? `${b.split(bNewLineSymbol, truncateThreshold).join(bNewLineSymbol)}\n` : b;
1611
+ aLength = _a.length;
1612
+ bLength = _b.length;
1613
+ }
1614
+ const truncated = aLength !== a.length || bLength !== b.length;
1615
+ const isCommon = (aIndex, bIndex) => a[aIndex] === b[bIndex];
1616
+ let aIndex = 0;
1617
+ let bIndex = 0;
1618
+ const diffs = [];
1619
+ const foundSubsequence = (nCommon, aCommon, bCommon) => {
1620
+ if (aIndex !== aCommon) {
1621
+ diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex, aCommon)));
1622
+ }
1623
+ if (bIndex !== bCommon) {
1624
+ diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex, bCommon)));
1625
+ }
1626
+ aIndex = aCommon + nCommon;
1627
+ bIndex = bCommon + nCommon;
1628
+ diffs.push(new Diff(DIFF_EQUAL, b.slice(bCommon, bIndex)));
1629
+ };
1630
+ diffSequences(aLength, bLength, isCommon, foundSubsequence);
1631
+ if (aIndex !== aLength) {
1632
+ diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex)));
1633
+ }
1634
+ if (bIndex !== bLength) {
1635
+ diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex)));
1636
+ }
1637
+ return [diffs, truncated];
1650
1638
  }
1651
1639
 
1652
1640
  function concatenateRelevantDiffs(op, diffs, changeColor) {
1653
- return diffs.reduce(
1654
- (reduced, diff) => reduced + (diff[0] === DIFF_EQUAL ? diff[1] : diff[0] === op && diff[1].length !== 0 ? changeColor(diff[1]) : ""),
1655
- ""
1656
- );
1641
+ return diffs.reduce((reduced, diff) => reduced + (diff[0] === DIFF_EQUAL ? diff[1] : diff[0] === op && diff[1].length !== 0 ? changeColor(diff[1]) : ""), "");
1657
1642
  }
1658
1643
  class ChangeBuffer {
1659
- op;
1660
- line;
1661
- // incomplete line
1662
- lines;
1663
- // complete lines
1664
- changeColor;
1665
- constructor(op, changeColor) {
1666
- this.op = op;
1667
- this.line = [];
1668
- this.lines = [];
1669
- this.changeColor = changeColor;
1670
- }
1671
- pushSubstring(substring) {
1672
- this.pushDiff(new Diff(this.op, substring));
1673
- }
1674
- pushLine() {
1675
- this.lines.push(
1676
- this.line.length !== 1 ? new Diff(
1677
- this.op,
1678
- concatenateRelevantDiffs(this.op, this.line, this.changeColor)
1679
- ) : this.line[0][0] === this.op ? this.line[0] : new Diff(this.op, this.line[0][1])
1680
- // was common diff
1681
- );
1682
- this.line.length = 0;
1683
- }
1684
- isLineEmpty() {
1685
- return this.line.length === 0;
1686
- }
1687
- // Minor input to buffer.
1688
- pushDiff(diff) {
1689
- this.line.push(diff);
1690
- }
1691
- // Main input to buffer.
1692
- align(diff) {
1693
- const string = diff[1];
1694
- if (string.includes("\n")) {
1695
- const substrings = string.split("\n");
1696
- const iLast = substrings.length - 1;
1697
- substrings.forEach((substring, i) => {
1698
- if (i < iLast) {
1699
- this.pushSubstring(substring);
1700
- this.pushLine();
1701
- } else if (substring.length !== 0) {
1702
- this.pushSubstring(substring);
1703
- }
1704
- });
1705
- } else {
1706
- this.pushDiff(diff);
1707
- }
1708
- }
1709
- // Output from buffer.
1710
- moveLinesTo(lines) {
1711
- if (!this.isLineEmpty()) {
1712
- this.pushLine();
1713
- }
1714
- lines.push(...this.lines);
1715
- this.lines.length = 0;
1716
- }
1644
+ op;
1645
+ line;
1646
+ lines;
1647
+ changeColor;
1648
+ constructor(op, changeColor) {
1649
+ this.op = op;
1650
+ this.line = [];
1651
+ this.lines = [];
1652
+ this.changeColor = changeColor;
1653
+ }
1654
+ pushSubstring(substring) {
1655
+ this.pushDiff(new Diff(this.op, substring));
1656
+ }
1657
+ pushLine() {
1658
+ this.lines.push(this.line.length !== 1 ? new Diff(this.op, concatenateRelevantDiffs(this.op, this.line, this.changeColor)) : this.line[0][0] === this.op ? this.line[0] : new Diff(this.op, this.line[0][1]));
1659
+ this.line.length = 0;
1660
+ }
1661
+ isLineEmpty() {
1662
+ return this.line.length === 0;
1663
+ }
1664
+ pushDiff(diff) {
1665
+ this.line.push(diff);
1666
+ }
1667
+ align(diff) {
1668
+ const string = diff[1];
1669
+ if (string.includes("\n")) {
1670
+ const substrings = string.split("\n");
1671
+ const iLast = substrings.length - 1;
1672
+ substrings.forEach((substring, i) => {
1673
+ if (i < iLast) {
1674
+ this.pushSubstring(substring);
1675
+ this.pushLine();
1676
+ } else if (substring.length !== 0) {
1677
+ this.pushSubstring(substring);
1678
+ }
1679
+ });
1680
+ } else {
1681
+ this.pushDiff(diff);
1682
+ }
1683
+ }
1684
+ moveLinesTo(lines) {
1685
+ if (!this.isLineEmpty()) {
1686
+ this.pushLine();
1687
+ }
1688
+ lines.push(...this.lines);
1689
+ this.lines.length = 0;
1690
+ }
1717
1691
  }
1718
1692
  class CommonBuffer {
1719
- deleteBuffer;
1720
- insertBuffer;
1721
- lines;
1722
- constructor(deleteBuffer, insertBuffer) {
1723
- this.deleteBuffer = deleteBuffer;
1724
- this.insertBuffer = insertBuffer;
1725
- this.lines = [];
1726
- }
1727
- pushDiffCommonLine(diff) {
1728
- this.lines.push(diff);
1729
- }
1730
- pushDiffChangeLines(diff) {
1731
- const isDiffEmpty = diff[1].length === 0;
1732
- if (!isDiffEmpty || this.deleteBuffer.isLineEmpty()) {
1733
- this.deleteBuffer.pushDiff(diff);
1734
- }
1735
- if (!isDiffEmpty || this.insertBuffer.isLineEmpty()) {
1736
- this.insertBuffer.pushDiff(diff);
1737
- }
1738
- }
1739
- flushChangeLines() {
1740
- this.deleteBuffer.moveLinesTo(this.lines);
1741
- this.insertBuffer.moveLinesTo(this.lines);
1742
- }
1743
- // Input to buffer.
1744
- align(diff) {
1745
- const op = diff[0];
1746
- const string = diff[1];
1747
- if (string.includes("\n")) {
1748
- const substrings = string.split("\n");
1749
- const iLast = substrings.length - 1;
1750
- substrings.forEach((substring, i) => {
1751
- if (i === 0) {
1752
- const subdiff = new Diff(op, substring);
1753
- if (this.deleteBuffer.isLineEmpty() && this.insertBuffer.isLineEmpty()) {
1754
- this.flushChangeLines();
1755
- this.pushDiffCommonLine(subdiff);
1756
- } else {
1757
- this.pushDiffChangeLines(subdiff);
1758
- this.flushChangeLines();
1759
- }
1760
- } else if (i < iLast) {
1761
- this.pushDiffCommonLine(new Diff(op, substring));
1762
- } else if (substring.length !== 0) {
1763
- this.pushDiffChangeLines(new Diff(op, substring));
1764
- }
1765
- });
1766
- } else {
1767
- this.pushDiffChangeLines(diff);
1768
- }
1769
- }
1770
- // Output from buffer.
1771
- getLines() {
1772
- this.flushChangeLines();
1773
- return this.lines;
1774
- }
1693
+ deleteBuffer;
1694
+ insertBuffer;
1695
+ lines;
1696
+ constructor(deleteBuffer, insertBuffer) {
1697
+ this.deleteBuffer = deleteBuffer;
1698
+ this.insertBuffer = insertBuffer;
1699
+ this.lines = [];
1700
+ }
1701
+ pushDiffCommonLine(diff) {
1702
+ this.lines.push(diff);
1703
+ }
1704
+ pushDiffChangeLines(diff) {
1705
+ const isDiffEmpty = diff[1].length === 0;
1706
+ if (!isDiffEmpty || this.deleteBuffer.isLineEmpty()) {
1707
+ this.deleteBuffer.pushDiff(diff);
1708
+ }
1709
+ if (!isDiffEmpty || this.insertBuffer.isLineEmpty()) {
1710
+ this.insertBuffer.pushDiff(diff);
1711
+ }
1712
+ }
1713
+ flushChangeLines() {
1714
+ this.deleteBuffer.moveLinesTo(this.lines);
1715
+ this.insertBuffer.moveLinesTo(this.lines);
1716
+ }
1717
+ align(diff) {
1718
+ const op = diff[0];
1719
+ const string = diff[1];
1720
+ if (string.includes("\n")) {
1721
+ const substrings = string.split("\n");
1722
+ const iLast = substrings.length - 1;
1723
+ substrings.forEach((substring, i) => {
1724
+ if (i === 0) {
1725
+ const subdiff = new Diff(op, substring);
1726
+ if (this.deleteBuffer.isLineEmpty() && this.insertBuffer.isLineEmpty()) {
1727
+ this.flushChangeLines();
1728
+ this.pushDiffCommonLine(subdiff);
1729
+ } else {
1730
+ this.pushDiffChangeLines(subdiff);
1731
+ this.flushChangeLines();
1732
+ }
1733
+ } else if (i < iLast) {
1734
+ this.pushDiffCommonLine(new Diff(op, substring));
1735
+ } else if (substring.length !== 0) {
1736
+ this.pushDiffChangeLines(new Diff(op, substring));
1737
+ }
1738
+ });
1739
+ } else {
1740
+ this.pushDiffChangeLines(diff);
1741
+ }
1742
+ }
1743
+ getLines() {
1744
+ this.flushChangeLines();
1745
+ return this.lines;
1746
+ }
1775
1747
  }
1776
1748
  function getAlignedDiffs(diffs, changeColor) {
1777
- const deleteBuffer = new ChangeBuffer(DIFF_DELETE, changeColor);
1778
- const insertBuffer = new ChangeBuffer(DIFF_INSERT, changeColor);
1779
- const commonBuffer = new CommonBuffer(deleteBuffer, insertBuffer);
1780
- diffs.forEach((diff) => {
1781
- switch (diff[0]) {
1782
- case DIFF_DELETE:
1783
- deleteBuffer.align(diff);
1784
- break;
1785
- case DIFF_INSERT:
1786
- insertBuffer.align(diff);
1787
- break;
1788
- default:
1789
- commonBuffer.align(diff);
1790
- }
1791
- });
1792
- return commonBuffer.getLines();
1749
+ const deleteBuffer = new ChangeBuffer(DIFF_DELETE, changeColor);
1750
+ const insertBuffer = new ChangeBuffer(DIFF_INSERT, changeColor);
1751
+ const commonBuffer = new CommonBuffer(deleteBuffer, insertBuffer);
1752
+ diffs.forEach((diff) => {
1753
+ switch (diff[0]) {
1754
+ case DIFF_DELETE:
1755
+ deleteBuffer.align(diff);
1756
+ break;
1757
+ case DIFF_INSERT:
1758
+ insertBuffer.align(diff);
1759
+ break;
1760
+ default: commonBuffer.align(diff);
1761
+ }
1762
+ });
1763
+ return commonBuffer.getLines();
1793
1764
  }
1794
1765
 
1795
1766
  function hasCommonDiff(diffs, isMultiline) {
1796
- if (isMultiline) {
1797
- const iLast = diffs.length - 1;
1798
- return diffs.some(
1799
- (diff, i) => diff[0] === DIFF_EQUAL && (i !== iLast || diff[1] !== "\n")
1800
- );
1801
- }
1802
- return diffs.some((diff) => diff[0] === DIFF_EQUAL);
1767
+ if (isMultiline) {
1768
+ const iLast = diffs.length - 1;
1769
+ return diffs.some((diff, i) => diff[0] === DIFF_EQUAL && (i !== iLast || diff[1] !== "\n"));
1770
+ }
1771
+ return diffs.some((diff) => diff[0] === DIFF_EQUAL);
1803
1772
  }
1804
1773
  function diffStringsUnified(a, b, options) {
1805
- if (a !== b && a.length !== 0 && b.length !== 0) {
1806
- const isMultiline = a.includes("\n") || b.includes("\n");
1807
- const [diffs, truncated] = diffStringsRaw(
1808
- isMultiline ? `${a}
1809
- ` : a,
1810
- isMultiline ? `${b}
1811
- ` : b,
1812
- true,
1813
- // cleanupSemantic
1814
- options
1815
- );
1816
- if (hasCommonDiff(diffs, isMultiline)) {
1817
- const optionsNormalized = normalizeDiffOptions(options);
1818
- const lines = getAlignedDiffs(diffs, optionsNormalized.changeColor);
1819
- return printDiffLines(lines, truncated, optionsNormalized);
1820
- }
1821
- }
1822
- return diffLinesUnified(a.split("\n"), b.split("\n"), options);
1774
+ if (a !== b && a.length !== 0 && b.length !== 0) {
1775
+ const isMultiline = a.includes("\n") || b.includes("\n");
1776
+ const [diffs, truncated] = diffStringsRaw(isMultiline ? `${a}\n` : a, isMultiline ? `${b}\n` : b, true, options);
1777
+ if (hasCommonDiff(diffs, isMultiline)) {
1778
+ const optionsNormalized = normalizeDiffOptions(options);
1779
+ const lines = getAlignedDiffs(diffs, optionsNormalized.changeColor);
1780
+ return printDiffLines(lines, truncated, optionsNormalized);
1781
+ }
1782
+ }
1783
+ return diffLinesUnified(a.split("\n"), b.split("\n"), options);
1823
1784
  }
1824
1785
  function diffStringsRaw(a, b, cleanup, options) {
1825
- const [diffs, truncated] = diffStrings(a, b, options);
1826
- if (cleanup) {
1827
- diff_cleanupSemantic(diffs);
1828
- }
1829
- return [diffs, truncated];
1786
+ const [diffs, truncated] = diffStrings(a, b, options);
1787
+ if (cleanup) {
1788
+ diff_cleanupSemantic(diffs);
1789
+ }
1790
+ return [diffs, truncated];
1830
1791
  }
1831
1792
 
1832
1793
  function getCommonMessage(message, options) {
1833
- const { commonColor } = normalizeDiffOptions(options);
1834
- return commonColor(message);
1794
+ const { commonColor } = normalizeDiffOptions(options);
1795
+ return commonColor(message);
1835
1796
  }
1836
- const {
1837
- AsymmetricMatcher,
1838
- DOMCollection,
1839
- DOMElement,
1840
- Immutable,
1841
- ReactElement,
1842
- ReactTestComponent
1843
- } = plugins;
1797
+ const { AsymmetricMatcher, DOMCollection, DOMElement, Immutable, ReactElement, ReactTestComponent } = plugins;
1844
1798
  const PLUGINS = [
1845
- ReactTestComponent,
1846
- ReactElement,
1847
- DOMElement,
1848
- DOMCollection,
1849
- Immutable,
1850
- AsymmetricMatcher,
1851
- plugins.Error
1799
+ ReactTestComponent,
1800
+ ReactElement,
1801
+ DOMElement,
1802
+ DOMCollection,
1803
+ Immutable,
1804
+ AsymmetricMatcher,
1805
+ plugins.Error
1852
1806
  ];
1853
1807
  const FORMAT_OPTIONS = {
1854
- maxDepth: 20,
1855
- plugins: PLUGINS
1808
+ maxDepth: 20,
1809
+ plugins: PLUGINS
1856
1810
  };
1857
1811
  const FALLBACK_FORMAT_OPTIONS = {
1858
- callToJSON: false,
1859
- maxDepth: 8,
1860
- plugins: PLUGINS
1812
+ callToJSON: false,
1813
+ maxDepth: 8,
1814
+ plugins: PLUGINS
1861
1815
  };
1816
+ /**
1817
+ * @param a Expected value
1818
+ * @param b Received value
1819
+ * @param options Diff options
1820
+ * @returns {string | null} a string diff
1821
+ */
1862
1822
  function diff(a, b, options) {
1863
- if (Object.is(a, b)) {
1864
- return "";
1865
- }
1866
- const aType = getType(a);
1867
- let expectedType = aType;
1868
- let omitDifference = false;
1869
- if (aType === "object" && typeof a.asymmetricMatch === "function") {
1870
- if (a.$$typeof !== Symbol.for("jest.asymmetricMatcher")) {
1871
- return void 0;
1872
- }
1873
- if (typeof a.getExpectedType !== "function") {
1874
- return void 0;
1875
- }
1876
- expectedType = a.getExpectedType();
1877
- omitDifference = expectedType === "string";
1878
- }
1879
- if (expectedType !== getType(b)) {
1880
- let truncate2 = function(s) {
1881
- return s.length <= MAX_LENGTH ? s : `${s.slice(0, MAX_LENGTH)}...`;
1882
- };
1883
- const { aAnnotation, aColor, aIndicator, bAnnotation, bColor, bIndicator } = normalizeDiffOptions(options);
1884
- const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
1885
- let aDisplay = format(a, formatOptions);
1886
- let bDisplay = format(b, formatOptions);
1887
- const MAX_LENGTH = 1e5;
1888
- aDisplay = truncate2(aDisplay);
1889
- bDisplay = truncate2(bDisplay);
1890
- const aDiff = `${aColor(`${aIndicator} ${aAnnotation}:`)}
1891
- ${aDisplay}`;
1892
- const bDiff = `${bColor(`${bIndicator} ${bAnnotation}:`)}
1893
- ${bDisplay}`;
1894
- return `${aDiff}
1895
-
1896
- ${bDiff}`;
1897
- }
1898
- if (omitDifference) {
1899
- return void 0;
1900
- }
1901
- switch (aType) {
1902
- case "string":
1903
- return diffLinesUnified(a.split("\n"), b.split("\n"), options);
1904
- case "boolean":
1905
- case "number":
1906
- return comparePrimitive(a, b, options);
1907
- case "map":
1908
- return compareObjects(sortMap(a), sortMap(b), options);
1909
- case "set":
1910
- return compareObjects(sortSet(a), sortSet(b), options);
1911
- default:
1912
- return compareObjects(a, b, options);
1913
- }
1823
+ if (Object.is(a, b)) {
1824
+ return "";
1825
+ }
1826
+ const aType = getType(a);
1827
+ let expectedType = aType;
1828
+ let omitDifference = false;
1829
+ if (aType === "object" && typeof a.asymmetricMatch === "function") {
1830
+ if (a.$$typeof !== Symbol.for("jest.asymmetricMatcher")) {
1831
+ return undefined;
1832
+ }
1833
+ if (typeof a.getExpectedType !== "function") {
1834
+ return undefined;
1835
+ }
1836
+ expectedType = a.getExpectedType();
1837
+ omitDifference = expectedType === "string";
1838
+ }
1839
+ if (expectedType !== getType(b)) {
1840
+ const { aAnnotation, aColor, aIndicator, bAnnotation, bColor, bIndicator } = normalizeDiffOptions(options);
1841
+ const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
1842
+ let aDisplay = format(a, formatOptions);
1843
+ let bDisplay = format(b, formatOptions);
1844
+ const MAX_LENGTH = 1e5;
1845
+ function truncate(s) {
1846
+ return s.length <= MAX_LENGTH ? s : `${s.slice(0, MAX_LENGTH)}...`;
1847
+ }
1848
+ aDisplay = truncate(aDisplay);
1849
+ bDisplay = truncate(bDisplay);
1850
+ const aDiff = `${aColor(`${aIndicator} ${aAnnotation}:`)} \n${aDisplay}`;
1851
+ const bDiff = `${bColor(`${bIndicator} ${bAnnotation}:`)} \n${bDisplay}`;
1852
+ return `${aDiff}\n\n${bDiff}`;
1853
+ }
1854
+ if (omitDifference) {
1855
+ return undefined;
1856
+ }
1857
+ switch (aType) {
1858
+ case "string": return diffLinesUnified(a.split("\n"), b.split("\n"), options);
1859
+ case "boolean":
1860
+ case "number": return comparePrimitive(a, b, options);
1861
+ case "map": return compareObjects(sortMap(a), sortMap(b), options);
1862
+ case "set": return compareObjects(sortSet(a), sortSet(b), options);
1863
+ default: return compareObjects(a, b, options);
1864
+ }
1914
1865
  }
1915
1866
  function comparePrimitive(a, b, options) {
1916
- const aFormat = format(a, FORMAT_OPTIONS);
1917
- const bFormat = format(b, FORMAT_OPTIONS);
1918
- return aFormat === bFormat ? "" : diffLinesUnified(aFormat.split("\n"), bFormat.split("\n"), options);
1867
+ const aFormat = format(a, FORMAT_OPTIONS);
1868
+ const bFormat = format(b, FORMAT_OPTIONS);
1869
+ return aFormat === bFormat ? "" : diffLinesUnified(aFormat.split("\n"), bFormat.split("\n"), options);
1919
1870
  }
1920
1871
  function sortMap(map) {
1921
- return new Map(Array.from(map.entries()).sort());
1872
+ return new Map(Array.from(map.entries()).sort());
1922
1873
  }
1923
1874
  function sortSet(set) {
1924
- return new Set(Array.from(set.values()).sort());
1875
+ return new Set(Array.from(set.values()).sort());
1925
1876
  }
1926
1877
  function compareObjects(a, b, options) {
1927
- let difference;
1928
- let hasThrown = false;
1929
- try {
1930
- const formatOptions = getFormatOptions(FORMAT_OPTIONS, options);
1931
- difference = getObjectsDifference(a, b, formatOptions, options);
1932
- } catch {
1933
- hasThrown = true;
1934
- }
1935
- const noDiffMessage = getCommonMessage(NO_DIFF_MESSAGE, options);
1936
- if (difference === void 0 || difference === noDiffMessage) {
1937
- const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
1938
- difference = getObjectsDifference(a, b, formatOptions, options);
1939
- if (difference !== noDiffMessage && !hasThrown) {
1940
- difference = `${getCommonMessage(
1941
- SIMILAR_MESSAGE,
1942
- options
1943
- )}
1944
-
1945
- ${difference}`;
1946
- }
1947
- }
1948
- return difference;
1878
+ let difference;
1879
+ let hasThrown = false;
1880
+ try {
1881
+ const formatOptions = getFormatOptions(FORMAT_OPTIONS, options);
1882
+ difference = getObjectsDifference(a, b, formatOptions, options);
1883
+ } catch {
1884
+ hasThrown = true;
1885
+ }
1886
+ const noDiffMessage = getCommonMessage(NO_DIFF_MESSAGE, options);
1887
+ if (difference === undefined || difference === noDiffMessage) {
1888
+ const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
1889
+ difference = getObjectsDifference(a, b, formatOptions, options);
1890
+ if (difference !== noDiffMessage && !hasThrown) {
1891
+ difference = `${getCommonMessage(SIMILAR_MESSAGE, options)}\n\n${difference}`;
1892
+ }
1893
+ }
1894
+ return difference;
1949
1895
  }
1950
1896
  function getFormatOptions(formatOptions, options) {
1951
- const { compareKeys, printBasicPrototype, maxDepth } = normalizeDiffOptions(options);
1952
- return {
1953
- ...formatOptions,
1954
- compareKeys,
1955
- printBasicPrototype,
1956
- maxDepth: maxDepth ?? formatOptions.maxDepth
1957
- };
1897
+ const { compareKeys, printBasicPrototype, maxDepth } = normalizeDiffOptions(options);
1898
+ return {
1899
+ ...formatOptions,
1900
+ compareKeys,
1901
+ printBasicPrototype,
1902
+ maxDepth: maxDepth ?? formatOptions.maxDepth
1903
+ };
1958
1904
  }
1959
1905
  function getObjectsDifference(a, b, formatOptions, options) {
1960
- const formatOptionsZeroIndent = { ...formatOptions, indent: 0 };
1961
- const aCompare = format(a, formatOptionsZeroIndent);
1962
- const bCompare = format(b, formatOptionsZeroIndent);
1963
- if (aCompare === bCompare) {
1964
- return getCommonMessage(NO_DIFF_MESSAGE, options);
1965
- } else {
1966
- const aDisplay = format(a, formatOptions);
1967
- const bDisplay = format(b, formatOptions);
1968
- return diffLinesUnified2(
1969
- aDisplay.split("\n"),
1970
- bDisplay.split("\n"),
1971
- aCompare.split("\n"),
1972
- bCompare.split("\n"),
1973
- options
1974
- );
1975
- }
1906
+ const formatOptionsZeroIndent = {
1907
+ ...formatOptions,
1908
+ indent: 0
1909
+ };
1910
+ const aCompare = format(a, formatOptionsZeroIndent);
1911
+ const bCompare = format(b, formatOptionsZeroIndent);
1912
+ if (aCompare === bCompare) {
1913
+ return getCommonMessage(NO_DIFF_MESSAGE, options);
1914
+ } else {
1915
+ const aDisplay = format(a, formatOptions);
1916
+ const bDisplay = format(b, formatOptions);
1917
+ return diffLinesUnified2(aDisplay.split("\n"), bDisplay.split("\n"), aCompare.split("\n"), bCompare.split("\n"), options);
1918
+ }
1976
1919
  }
1977
1920
  const MAX_DIFF_STRING_LENGTH = 2e4;
1978
1921
  function isAsymmetricMatcher(data) {
1979
- const type = getType$1(data);
1980
- return type === "Object" && typeof data.asymmetricMatch === "function";
1922
+ const type = getType$1(data);
1923
+ return type === "Object" && typeof data.asymmetricMatch === "function";
1981
1924
  }
1982
1925
  function isReplaceable(obj1, obj2) {
1983
- const obj1Type = getType$1(obj1);
1984
- const obj2Type = getType$1(obj2);
1985
- return obj1Type === obj2Type && (obj1Type === "Object" || obj1Type === "Array");
1926
+ const obj1Type = getType$1(obj1);
1927
+ const obj2Type = getType$1(obj2);
1928
+ return obj1Type === obj2Type && (obj1Type === "Object" || obj1Type === "Array");
1986
1929
  }
1987
1930
  function printDiffOrStringify(received, expected, options) {
1988
- const { aAnnotation, bAnnotation } = normalizeDiffOptions(options);
1989
- if (typeof expected === "string" && typeof received === "string" && expected.length > 0 && received.length > 0 && expected.length <= MAX_DIFF_STRING_LENGTH && received.length <= MAX_DIFF_STRING_LENGTH && expected !== received) {
1990
- if (expected.includes("\n") || received.includes("\n")) {
1991
- return diffStringsUnified(expected, received, options);
1992
- }
1993
- const [diffs] = diffStringsRaw(expected, received, true);
1994
- const hasCommonDiff = diffs.some((diff2) => diff2[0] === DIFF_EQUAL);
1995
- const printLabel = getLabelPrinter(aAnnotation, bAnnotation);
1996
- const expectedLine = printLabel(aAnnotation) + printExpected(
1997
- getCommonAndChangedSubstrings(diffs, DIFF_DELETE, hasCommonDiff)
1998
- );
1999
- const receivedLine = printLabel(bAnnotation) + printReceived(
2000
- getCommonAndChangedSubstrings(diffs, DIFF_INSERT, hasCommonDiff)
2001
- );
2002
- return `${expectedLine}
2003
- ${receivedLine}`;
2004
- }
2005
- const clonedExpected = deepClone(expected, { forceWritable: true });
2006
- const clonedReceived = deepClone(received, { forceWritable: true });
2007
- const { replacedExpected, replacedActual } = replaceAsymmetricMatcher(clonedReceived, clonedExpected);
2008
- const difference = diff(replacedExpected, replacedActual, options);
2009
- return difference;
1931
+ const { aAnnotation, bAnnotation } = normalizeDiffOptions(options);
1932
+ if (typeof expected === "string" && typeof received === "string" && expected.length > 0 && received.length > 0 && expected.length <= MAX_DIFF_STRING_LENGTH && received.length <= MAX_DIFF_STRING_LENGTH && expected !== received) {
1933
+ if (expected.includes("\n") || received.includes("\n")) {
1934
+ return diffStringsUnified(expected, received, options);
1935
+ }
1936
+ const [diffs] = diffStringsRaw(expected, received, true);
1937
+ const hasCommonDiff = diffs.some((diff) => diff[0] === DIFF_EQUAL);
1938
+ const printLabel = getLabelPrinter(aAnnotation, bAnnotation);
1939
+ const expectedLine = printLabel(aAnnotation) + printExpected(getCommonAndChangedSubstrings(diffs, DIFF_DELETE, hasCommonDiff));
1940
+ const receivedLine = printLabel(bAnnotation) + printReceived(getCommonAndChangedSubstrings(diffs, DIFF_INSERT, hasCommonDiff));
1941
+ return `${expectedLine}\n${receivedLine}`;
1942
+ }
1943
+ const clonedExpected = deepClone(expected, { forceWritable: true });
1944
+ const clonedReceived = deepClone(received, { forceWritable: true });
1945
+ const { replacedExpected, replacedActual } = replaceAsymmetricMatcher(clonedReceived, clonedExpected);
1946
+ const difference = diff(replacedExpected, replacedActual, options);
1947
+ return difference;
2010
1948
  }
2011
- function replaceAsymmetricMatcher(actual, expected, actualReplaced = /* @__PURE__ */ new WeakSet(), expectedReplaced = /* @__PURE__ */ new WeakSet()) {
2012
- if (actual instanceof Error && expected instanceof Error && typeof actual.cause !== "undefined" && typeof expected.cause === "undefined") {
2013
- delete actual.cause;
2014
- return {
2015
- replacedActual: actual,
2016
- replacedExpected: expected
2017
- };
2018
- }
2019
- if (!isReplaceable(actual, expected)) {
2020
- return { replacedActual: actual, replacedExpected: expected };
2021
- }
2022
- if (actualReplaced.has(actual) || expectedReplaced.has(expected)) {
2023
- return { replacedActual: actual, replacedExpected: expected };
2024
- }
2025
- actualReplaced.add(actual);
2026
- expectedReplaced.add(expected);
2027
- getOwnProperties(expected).forEach((key) => {
2028
- const expectedValue = expected[key];
2029
- const actualValue = actual[key];
2030
- if (isAsymmetricMatcher(expectedValue)) {
2031
- if (expectedValue.asymmetricMatch(actualValue)) {
2032
- actual[key] = expectedValue;
2033
- }
2034
- } else if (isAsymmetricMatcher(actualValue)) {
2035
- if (actualValue.asymmetricMatch(expectedValue)) {
2036
- expected[key] = actualValue;
2037
- }
2038
- } else if (isReplaceable(actualValue, expectedValue)) {
2039
- const replaced = replaceAsymmetricMatcher(
2040
- actualValue,
2041
- expectedValue,
2042
- actualReplaced,
2043
- expectedReplaced
2044
- );
2045
- actual[key] = replaced.replacedActual;
2046
- expected[key] = replaced.replacedExpected;
2047
- }
2048
- });
2049
- return {
2050
- replacedActual: actual,
2051
- replacedExpected: expected
2052
- };
1949
+ function replaceAsymmetricMatcher(actual, expected, actualReplaced = new WeakSet(), expectedReplaced = new WeakSet()) {
1950
+ if (actual instanceof Error && expected instanceof Error && typeof actual.cause !== "undefined" && typeof expected.cause === "undefined") {
1951
+ delete actual.cause;
1952
+ return {
1953
+ replacedActual: actual,
1954
+ replacedExpected: expected
1955
+ };
1956
+ }
1957
+ if (!isReplaceable(actual, expected)) {
1958
+ return {
1959
+ replacedActual: actual,
1960
+ replacedExpected: expected
1961
+ };
1962
+ }
1963
+ if (actualReplaced.has(actual) || expectedReplaced.has(expected)) {
1964
+ return {
1965
+ replacedActual: actual,
1966
+ replacedExpected: expected
1967
+ };
1968
+ }
1969
+ actualReplaced.add(actual);
1970
+ expectedReplaced.add(expected);
1971
+ getOwnProperties(expected).forEach((key) => {
1972
+ const expectedValue = expected[key];
1973
+ const actualValue = actual[key];
1974
+ if (isAsymmetricMatcher(expectedValue)) {
1975
+ if (expectedValue.asymmetricMatch(actualValue)) {
1976
+ actual[key] = expectedValue;
1977
+ }
1978
+ } else if (isAsymmetricMatcher(actualValue)) {
1979
+ if (actualValue.asymmetricMatch(expectedValue)) {
1980
+ expected[key] = actualValue;
1981
+ }
1982
+ } else if (isReplaceable(actualValue, expectedValue)) {
1983
+ const replaced = replaceAsymmetricMatcher(actualValue, expectedValue, actualReplaced, expectedReplaced);
1984
+ actual[key] = replaced.replacedActual;
1985
+ expected[key] = replaced.replacedExpected;
1986
+ }
1987
+ });
1988
+ return {
1989
+ replacedActual: actual,
1990
+ replacedExpected: expected
1991
+ };
2053
1992
  }
2054
1993
  function getLabelPrinter(...strings) {
2055
- const maxLength = strings.reduce(
2056
- (max, string) => string.length > max ? string.length : max,
2057
- 0
2058
- );
2059
- return (string) => `${string}: ${" ".repeat(maxLength - string.length)}`;
1994
+ const maxLength = strings.reduce((max, string) => string.length > max ? string.length : max, 0);
1995
+ return (string) => `${string}: ${" ".repeat(maxLength - string.length)}`;
2060
1996
  }
2061
- const SPACE_SYMBOL = "\xB7";
1997
+ const SPACE_SYMBOL = "·";
2062
1998
  function replaceTrailingSpaces(text) {
2063
- return text.replace(/\s+$/gm, (spaces) => SPACE_SYMBOL.repeat(spaces.length));
1999
+ return text.replace(/\s+$/gm, (spaces) => SPACE_SYMBOL.repeat(spaces.length));
2064
2000
  }
2065
2001
  function printReceived(object) {
2066
- return c.red(replaceTrailingSpaces(stringify(object)));
2002
+ return c.red(replaceTrailingSpaces(stringify(object)));
2067
2003
  }
2068
2004
  function printExpected(value) {
2069
- return c.green(replaceTrailingSpaces(stringify(value)));
2005
+ return c.green(replaceTrailingSpaces(stringify(value)));
2070
2006
  }
2071
2007
  function getCommonAndChangedSubstrings(diffs, op, hasCommonDiff) {
2072
- return diffs.reduce(
2073
- (reduced, diff2) => reduced + (diff2[0] === DIFF_EQUAL ? diff2[1] : diff2[0] === op ? hasCommonDiff ? c.inverse(diff2[1]) : diff2[1] : ""),
2074
- ""
2075
- );
2008
+ return diffs.reduce((reduced, diff) => reduced + (diff[0] === DIFF_EQUAL ? diff[1] : diff[0] === op ? hasCommonDiff ? c.inverse(diff[1]) : diff[1] : ""), "");
2076
2009
  }
2077
2010
 
2078
2011
  export { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, Diff, diff, diffLinesRaw, diffLinesUnified, diffLinesUnified2, diffStringsRaw, diffStringsUnified, getLabelPrinter, printDiffOrStringify, replaceAsymmetricMatcher };