@@ -244,7 +244,7 @@ abstract class BaseFormatter<
244
244
for ( let index = 0 ; index < keys . length ; index ++ ) {
245
245
const key = keys [ index ] ;
246
246
if ( key === undefined ) continue ;
247
- const isLast = index === length - 1 ;
247
+ const isLast = index === keys . length - 1 ;
248
248
fn (
249
249
// for object diff, the delta key and left key are the same
250
250
key ,
@@ -310,8 +310,6 @@ abstract class BaseFormatter<
310
310
rightIndex < rightLength ||
311
311
`${ rightIndex } ` in arrayDelta
312
312
) {
313
- const isLast =
314
- leftIndex === leftLength - 1 || rightIndex === rightLength - 1 ;
315
313
let hasDelta = false ;
316
314
317
315
const leftIndexKey = `_${ leftIndex } ` as const ;
@@ -333,7 +331,12 @@ abstract class BaseFormatter<
333
331
value : leftArray ? leftArray [ movedFromIndex ] : undefined ,
334
332
}
335
333
: undefined ,
336
- isLast && ! ( rightIndexKey in arrayDelta ) ,
334
+
335
+ // is this the last key in this delta?
336
+ leftIndex === leftLength - 1 &&
337
+ rightIndex === rightLength - 1 &&
338
+ ! ( `${ rightIndex + 1 } ` in arrayDelta ) &&
339
+ ! ( rightIndexKey in arrayDelta ) ,
337
340
) ;
338
341
339
342
if ( Array . isArray ( itemDelta ) ) {
@@ -357,6 +360,7 @@ abstract class BaseFormatter<
357
360
// something happened to the right item at this position
358
361
hasDelta = true ;
359
362
const itemDelta = arrayDelta [ rightIndexKey ] ;
363
+ const isItemAdded = Array . isArray ( itemDelta ) && itemDelta . length === 1 ;
360
364
fn (
361
365
rightIndexKey ,
362
366
movedFromIndex ?? leftIndex ,
@@ -366,10 +370,14 @@ abstract class BaseFormatter<
366
370
value : leftArray ? leftArray [ movedFromIndex ] : undefined ,
367
371
}
368
372
: undefined ,
369
- isLast ,
373
+ // is this the last key in this delta?
374
+ leftIndex === leftLength - 1 &&
375
+ rightIndex === rightLength - 1 + ( isItemAdded ? 1 : 0 ) &&
376
+ ! ( `_${ leftIndex + 1 } ` in arrayDelta ) &&
377
+ ! ( `${ rightIndex + 1 } ` in arrayDelta ) ,
370
378
) ;
371
379
372
- if ( Array . isArray ( itemDelta ) && itemDelta . length === 1 ) {
380
+ if ( isItemAdded ) {
373
381
// added
374
382
rightLength ++ ;
375
383
rightIndex ++ ;
@@ -398,7 +406,10 @@ abstract class BaseFormatter<
398
406
value : leftArray ? leftArray [ movedFromIndex ] : undefined ,
399
407
}
400
408
: undefined ,
401
- isLast ,
409
+ // is this the last key in this delta?
410
+ leftIndex === leftLength - 1 &&
411
+ rightIndex === rightLength - 1 &&
412
+ ! ( `${ rightIndex + 1 } ` in arrayDelta ) ,
402
413
) ;
403
414
}
404
415
@@ -446,9 +457,7 @@ abstract class BaseFormatter<
446
457
parseTextDiff ( value : string ) {
447
458
const output = [ ] ;
448
459
const lines = value . split ( "\n@@ " ) ;
449
- // for (let i = 0, l = lines.length; i < l; i++) {
450
460
for ( const line of lines ) {
451
- //const line = lines[i];
452
461
const lineOutput : {
453
462
pieces : LineOutputPiece [ ] ;
454
463
location ?: LineOutputLocation ;
0 commit comments