1+ import concat from './utils/concat' ;
12import detectCircular from './utils/detect-circular' ;
23import diffArrayLCS from './utils/diff-array-lcs' ;
34import diffArrayNormal from './utils/diff-array-normal' ;
@@ -122,6 +123,10 @@ export type ArrayDiffFunc = (
122123 ...args : any [ ]
123124) => [ DiffResult [ ] , DiffResult [ ] ] ;
124125
126+ const EQUAL_EMPTY_LINE : DiffResult = { level : 0 , type : 'equal' , text : '' } ;
127+ const EQUAL_LEFT_BRACKET_LINE : DiffResult = { level : 0 , type : 'equal' , text : '{' } ;
128+ const EQUAL_RIGHT_BRACKET_LINE : DiffResult = { level : 0 , type : 'equal' , text : '}' } ;
129+
125130class Differ {
126131 private options : DifferOptions ;
127132 private arrayDiffFunc : ArrayDiffFunc ;
@@ -243,14 +248,14 @@ class Differ {
243248 } ) ) ;
244249 const lLength = resultLeft . length ;
245250 const rLength = resultRight . length ;
246- resultLeft . push ( ... Array ( rLength ) . fill ( { level : 0 , type : 'equal' , text : '' } ) ) ;
247- resultRight . unshift ( ... Array ( lLength ) . fill ( { level : 0 , type : 'equal' , text : '' } ) ) ;
251+ resultLeft = concat ( resultLeft , Array ( rLength ) . fill ( EQUAL_EMPTY_LINE ) ) ;
252+ resultRight = concat ( resultRight , Array ( lLength ) . fill ( EQUAL_EMPTY_LINE ) , true ) ;
248253 } else if ( typeLeft === 'object' ) {
249254 [ resultLeft , resultRight ] = diffObject ( sourceLeft , sourceRight , 1 , this . options , this . arrayDiffFunc ) ;
250- resultLeft . unshift ( { level : 0 , type : 'equal' , text : '{' } ) ;
251- resultLeft . push ( { level : 0 , type : 'equal' , text : '}' } ) ;
252- resultRight . unshift ( { level : 0 , type : 'equal' , text : '{' } ) ;
253- resultRight . push ( { level : 0 , type : 'equal' , text : '}' } ) ;
255+ resultLeft . unshift ( EQUAL_LEFT_BRACKET_LINE ) ;
256+ resultLeft . push ( EQUAL_RIGHT_BRACKET_LINE ) ;
257+ resultRight . unshift ( EQUAL_LEFT_BRACKET_LINE ) ;
258+ resultRight . push ( EQUAL_RIGHT_BRACKET_LINE ) ;
254259 } else if ( typeLeft === 'array' ) {
255260 [ resultLeft , resultRight ] = this . arrayDiffFunc ( sourceLeft , sourceRight , '' , '' , 0 , this . options ) ;
256261 } else if ( sourceLeft !== sourceRight ) {
@@ -269,10 +274,10 @@ class Differ {
269274 } else {
270275 resultLeft = [
271276 { level : 0 , type : 'remove' , text : stringify ( sourceLeft , null , null , this . options . maxDepth ) } ,
272- { level : 0 , type : 'equal' , text : '' } ,
277+ EQUAL_EMPTY_LINE ,
273278 ] ;
274279 resultRight = [
275- { level : 0 , type : 'equal' , text : '' } ,
280+ EQUAL_EMPTY_LINE ,
276281 { level : 0 , type : 'add' , text : stringify ( sourceRight , null , null , this . options . maxDepth ) } ,
277282 ] ;
278283 }
0 commit comments