fix(runtime-core): fix priority of option merging (#2041)

This commit is contained in:
ᴜɴвʏтᴇ 2020-09-03 09:35:43 -05:00 committed by GitHub
parent 71b6fedcdb
commit 95c07d8c36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

View File

@ -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', () => {

View File

@ -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]
}
}
}