Skip to content

Commit

Permalink
fix(shared): fix merge empty object is not work (#2841)
Browse files Browse the repository at this point in the history
* fix(shared): fix merge empty object is not work

* fix(shared): fix ci
  • Loading branch information
janryWang committed Feb 21, 2022
1 parent c38e728 commit 28a5853
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 13 additions & 0 deletions packages/shared/src/__tests__/index.spec.ts
Expand Up @@ -698,6 +698,19 @@ describe('merge', () => {
})
})

test('empty', () => {
expect(
merge(
{
aa: undefined,
},
{
aa: {},
}
)
).toEqual({ aa: {} })
})

test('clone', () => {
const target = {
aa: {
Expand Down
7 changes: 3 additions & 4 deletions packages/shared/src/merge.ts
@@ -1,4 +1,4 @@
import { isValid } from './isEmpty'
import { isValid, isEmpty } from './isEmpty'
import { isFn, isPlainObj } from './checkers'

function defaultIsMergeableObject(value: any) {
Expand Down Expand Up @@ -99,10 +99,9 @@ function mergeObject(target: any, source: any, options: Options) {
if (propertyIsUnsafe(target, key)) {
return
}
if (!target[key]) {
if (isEmpty(target[key])) {
destination[key] = source[key]
}
if (
} else if (
propertyIsOnObject(target, key) &&
options.isMergeableObject(source[key])
) {
Expand Down

0 comments on commit 28a5853

Please sign in to comment.