Skip to content

Commit

Permalink
remove unecessary check and reorder for positive checks instead of ne…
Browse files Browse the repository at this point in the history
…gative ones
  • Loading branch information
Tim Trinidad committed May 1, 2019
1 parent af7261b commit c9d1aff
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/jest-snapshot/src/utils.ts
Expand Up @@ -186,15 +186,15 @@ const deepMergeArray = (target: Array<any>, source: Array<any>) => {
const targetElement = mergedOutput[index];
const targetElementType = typeof targetElement;

if (targetElementType === 'undefined' || targetElementType !== 'object') {
// Source does not exist in target or target is primitive and cannot be deep merged
mergedOutput[index] = sourceElement;
} else if (Array.isArray(target[index])) {
if (Array.isArray(target[index])) {
// Target is an array
mergedOutput[index] = deepMergeArray(target[index], sourceElement);
} else {
// Target is an object - recursively merge
} else if (targetElementType === 'object') {
// Target is a (non-array) object - recursively merge
mergedOutput[index] = deepMerge(target[index], sourceElement);
} else {
// Source does not exist in target or target is primitive and cannot be deep merged
mergedOutput[index] = sourceElement;
}
});

Expand Down

0 comments on commit c9d1aff

Please sign in to comment.