@@ -29,7 +29,7 @@ export default function diff(
29
29
obj : Record < string , any > | any [ ] ,
30
30
newObj : Record < string , any > | any [ ] ,
31
31
options : Partial < Options > = { cyclesFix : true } ,
32
- _stack : Record < string , any > [ ] = [ ]
32
+ _stack : Record < string , any > [ ] = [ ] ,
33
33
) : Difference [ ] {
34
34
let diffs : Difference [ ] = [ ] ;
35
35
const isObjArray = Array . isArray ( obj ) ;
@@ -46,32 +46,34 @@ export default function diff(
46
46
continue ;
47
47
}
48
48
const newObjKey = newObj [ key ] ;
49
- const areObjects =
50
- typeof objKey === "object" && typeof newObjKey === "object" ;
49
+ const areCompatibleObjects =
50
+ typeof objKey === "object" &&
51
+ typeof newObjKey === "object" &&
52
+ Array . isArray ( objKey ) === Array . isArray ( newObjKey ) ;
51
53
if (
52
54
objKey &&
53
55
newObjKey &&
54
- areObjects &&
56
+ areCompatibleObjects &&
55
57
! richTypes [ Object . getPrototypeOf ( objKey ) ?. constructor ?. name ] &&
56
58
( ! options . cyclesFix || ! _stack . includes ( objKey ) )
57
59
) {
58
60
const nestedDiffs = diff (
59
61
objKey ,
60
62
newObjKey ,
61
63
options ,
62
- options . cyclesFix ? _stack . concat ( [ objKey ] ) : [ ]
64
+ options . cyclesFix ? _stack . concat ( [ objKey ] ) : [ ] ,
63
65
) ;
64
66
diffs . push . apply (
65
67
diffs ,
66
68
nestedDiffs . map ( ( difference ) => {
67
69
difference . path . unshift ( path ) ;
68
70
return difference ;
69
- } )
71
+ } ) ,
70
72
) ;
71
73
} else if (
72
74
objKey !== newObjKey &&
73
75
! (
74
- areObjects &&
76
+ areCompatibleObjects &&
75
77
( isNaN ( objKey )
76
78
? objKey + "" === newObjKey + ""
77
79
: + objKey === + newObjKey )
0 commit comments