Skip to content

Commit 652251c

Browse files
committed
fix: remove unnecessary isObjectNotArray guard in compareDeepIfVisited
1 parent 4a00a62 commit 652251c

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

lib/mergeDeep.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,13 @@ class MergeDeep {
248248
modifications.push({})
249249
additions.push({})
250250
deletions.push({})
251-
// visited[id] may be a primitive string (from the non-object branch in processArrays)
252-
// — only deep-compare when both sides are real objects
253-
if (this.isObjectNotArray(visited[id])) {
254-
// Strip the identity field before comparing — it was already used for matching
255-
const idPropA = NAME_USERNAME_PROPERTY(a)
256-
const idPropV = NAME_USERNAME_PROPERTY(visited[id])
257-
const targetObj = idPropA ? Object.fromEntries(Object.entries(a).filter(([k]) => k !== idPropA)) : a
258-
const sourceObj = idPropV ? Object.fromEntries(Object.entries(visited[id]).filter(([k]) => k !== idPropV)) : visited[id]
259-
this.compareDeep(targetObj, sourceObj, additions[additions.length - 1], modifications[modifications.length - 1], deletions[deletions.length - 1])
260-
}
251+
// Strip the identity field before comparing — it was already used for matching
252+
// and would otherwise appear as a spurious diff (e.g. slug vs name)
253+
const idPropA = NAME_USERNAME_PROPERTY(a)
254+
const idPropV = NAME_USERNAME_PROPERTY(visited[id])
255+
const targetObj = idPropA ? Object.fromEntries(Object.entries(a).filter(([k]) => k !== idPropA)) : a
256+
const sourceObj = idPropV ? Object.fromEntries(Object.entries(visited[id]).filter(([k]) => k !== idPropV)) : visited[id]
257+
this.compareDeep(targetObj, sourceObj, additions[additions.length - 1], modifications[modifications.length - 1], deletions[deletions.length - 1])
261258
// Any addtions for the matching key must be moved to modifications
262259
const lastAddition = additions[additions.length - 1]
263260
const lastModification = modifications[modifications.length - 1]
@@ -277,7 +274,7 @@ class MergeDeep {
277274
}
278275
// Add name attribute to the modifications to make it look better ; it won't be added otherwise as it would be the same
279276
if (!this.isEmpty(modifications[modifications.length - 1])) {
280-
if (this.isObjectNotArray(visited[id])) {
277+
if (visited[id]) {
281278
modifications[modifications.length - 1][NAME_USERNAME_PROPERTY(a)] = id
282279
}
283280
}

0 commit comments

Comments
 (0)