diff --git a/.changeset/tall-socks-listen.md b/.changeset/tall-socks-listen.md new file mode 100644 index 000000000000..af99a409f0f0 --- /dev/null +++ b/.changeset/tall-socks-listen.md @@ -0,0 +1,8 @@ +--- +'@modern-js/runtime': patch +'@modern-js/runtime-utils': patch +--- + +fix: mergeConfig function to return an object when the first configuration is not an object + +fix: 修复 mergeConfig 函数,使其在第一个配置非对象时返回对象 diff --git a/packages/runtime/plugin-runtime/src/core/plugin/index.ts b/packages/runtime/plugin-runtime/src/core/plugin/index.ts index 57e43f2cfc07..590ed85129f3 100644 --- a/packages/runtime/plugin-runtime/src/core/plugin/index.ts +++ b/packages/runtime/plugin-runtime/src/core/plugin/index.ts @@ -32,5 +32,5 @@ export function mergeConfig( config: Record, ...otherConfig: Record[] ) { - return merge(config, ...otherConfig); + return merge({}, config, ...otherConfig); } diff --git a/packages/toolkit/runtime-utils/tests/merge.test.ts b/packages/toolkit/runtime-utils/tests/merge.test.ts index d03495ba7d9e..6cf754752304 100644 --- a/packages/toolkit/runtime-utils/tests/merge.test.ts +++ b/packages/toolkit/runtime-utils/tests/merge.test.ts @@ -51,4 +51,10 @@ describe('merge function', () => { const result = merge({}, obj1, obj2, obj3); expect(result).toEqual({ a: 3 }); }); + test('should return right value when item is not object', () => { + expect(merge({}, true as any, { a: 1 })).toEqual({ a: 1 }); + expect(merge({}, false as any, { a: 1 })).toEqual({ a: 1 }); + expect(merge({}, 1 as any, { a: 1 })).toEqual({ a: 1 }); + expect(merge({}, 'b' as any, { a: 1 })).toEqual({ a: 1 }); + }); });