From 95c07d8c36a69bfc29e661fbbfb92735c4fe5d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=9C=C9=B4=D0=B2=CA=8F=D1=82=E1=B4=87?= Date: Thu, 3 Sep 2020 09:35:43 -0500 Subject: [PATCH] fix(runtime-core): fix priority of option merging (#2041) --- .../runtime-core/__tests__/apiCreateApp.spec.ts | 2 +- packages/runtime-core/src/componentOptions.ts | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/runtime-core/__tests__/apiCreateApp.spec.ts b/packages/runtime-core/__tests__/apiCreateApp.spec.ts index 0c7faf71..c3be3476 100644 --- a/packages/runtime-core/__tests__/apiCreateApp.spec.ts +++ b/packages/runtime-core/__tests__/apiCreateApp.spec.ts @@ -457,7 +457,7 @@ describe('api: createApp', () => { app.config.optionMergeStrategies.foo = (a, b) => (a ? `${a},` : ``) + b app.mount(nodeOps.createElement('div')) - expect(merged!).toBe('local,extends,mixin,global') + expect(merged!).toBe('global,extends,mixin,local') }) test('config.globalProperties', () => { diff --git a/packages/runtime-core/src/componentOptions.ts b/packages/runtime-core/src/componentOptions.ts index 5af8c410..fd473714 100644 --- a/packages/runtime-core/src/componentOptions.ts +++ b/packages/runtime-core/src/componentOptions.ts @@ -768,23 +768,24 @@ export function resolveMergedOptions( const globalMixins = instance.appContext.mixins if (!globalMixins.length && !mixins && !extendsOptions) return raw const options = {} - mergeOptions(options, raw, instance) globalMixins.forEach(m => mergeOptions(options, m, instance)) + mergeOptions(options, raw, instance) return (raw.__merged = options) } function mergeOptions(to: any, from: any, instance: ComponentInternalInstance) { const strats = instance.appContext.config.optionMergeStrategies - for (const key in from) { - if (strats && hasOwn(strats, key)) { - to[key] = strats[key](to[key], from[key], instance.proxy, key) - } else if (!hasOwn(to, key)) { - to[key] = from[key] - } - } const { mixins, extends: extendsOptions } = from extendsOptions && mergeOptions(to, extendsOptions, instance) mixins && mixins.forEach((m: ComponentOptionsMixin) => mergeOptions(to, m, instance)) + + for (const key in from) { + if (strats && hasOwn(strats, key)) { + to[key] = strats[key](to[key], from[key], instance.proxy, key) + } else { + to[key] = from[key] + } + } }