1
+ import concat from './utils/concat' ;
1
2
import detectCircular from './utils/detect-circular' ;
2
3
import diffArrayLCS from './utils/diff-array-lcs' ;
3
4
import diffArrayNormal from './utils/diff-array-normal' ;
@@ -122,6 +123,10 @@ export type ArrayDiffFunc = (
122
123
...args : any [ ]
123
124
) => [ DiffResult [ ] , DiffResult [ ] ] ;
124
125
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
+
125
130
class Differ {
126
131
private options : DifferOptions ;
127
132
private arrayDiffFunc : ArrayDiffFunc ;
@@ -243,14 +248,14 @@ class Differ {
243
248
} ) ) ;
244
249
const lLength = resultLeft . length ;
245
250
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 ) ;
248
253
} else if ( typeLeft === 'object' ) {
249
254
[ 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 ) ;
254
259
} else if ( typeLeft === 'array' ) {
255
260
[ resultLeft , resultRight ] = this . arrayDiffFunc ( sourceLeft , sourceRight , '' , '' , 0 , this . options ) ;
256
261
} else if ( sourceLeft !== sourceRight ) {
@@ -269,10 +274,10 @@ class Differ {
269
274
} else {
270
275
resultLeft = [
271
276
{ level : 0 , type : 'remove' , text : stringify ( sourceLeft , null , null , this . options . maxDepth ) } ,
272
- { level : 0 , type : 'equal' , text : '' } ,
277
+ EQUAL_EMPTY_LINE ,
273
278
] ;
274
279
resultRight = [
275
- { level : 0 , type : 'equal' , text : '' } ,
280
+ EQUAL_EMPTY_LINE ,
276
281
{ level : 0 , type : 'add' , text : stringify ( sourceRight , null , null , this . options . maxDepth ) } ,
277
282
] ;
278
283
}
0 commit comments