fix(runtime-core): fix priority of option merging (#2041)
This commit is contained in:
parent
71b6fedcdb
commit
95c07d8c36
@ -457,7 +457,7 @@ describe('api: createApp', () => {
|
|||||||
app.config.optionMergeStrategies.foo = (a, b) => (a ? `${a},` : ``) + b
|
app.config.optionMergeStrategies.foo = (a, b) => (a ? `${a},` : ``) + b
|
||||||
|
|
||||||
app.mount(nodeOps.createElement('div'))
|
app.mount(nodeOps.createElement('div'))
|
||||||
expect(merged!).toBe('local,extends,mixin,global')
|
expect(merged!).toBe('global,extends,mixin,local')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('config.globalProperties', () => {
|
test('config.globalProperties', () => {
|
||||||
|
@ -768,23 +768,24 @@ export function resolveMergedOptions(
|
|||||||
const globalMixins = instance.appContext.mixins
|
const globalMixins = instance.appContext.mixins
|
||||||
if (!globalMixins.length && !mixins && !extendsOptions) return raw
|
if (!globalMixins.length && !mixins && !extendsOptions) return raw
|
||||||
const options = {}
|
const options = {}
|
||||||
mergeOptions(options, raw, instance)
|
|
||||||
globalMixins.forEach(m => mergeOptions(options, m, instance))
|
globalMixins.forEach(m => mergeOptions(options, m, instance))
|
||||||
|
mergeOptions(options, raw, instance)
|
||||||
return (raw.__merged = options)
|
return (raw.__merged = options)
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeOptions(to: any, from: any, instance: ComponentInternalInstance) {
|
function mergeOptions(to: any, from: any, instance: ComponentInternalInstance) {
|
||||||
const strats = instance.appContext.config.optionMergeStrategies
|
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
|
const { mixins, extends: extendsOptions } = from
|
||||||
|
|
||||||
extendsOptions && mergeOptions(to, extendsOptions, instance)
|
extendsOptions && mergeOptions(to, extendsOptions, instance)
|
||||||
mixins &&
|
mixins &&
|
||||||
mixins.forEach((m: ComponentOptionsMixin) => mergeOptions(to, m, instance))
|
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]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user