Skip to content

Commit

Permalink
fix(runtime-core): fix priority of option merging (#2041)
Browse files Browse the repository at this point in the history
  • Loading branch information
unbyte authored Sep 3, 2020
1 parent 71b6fed commit 95c07d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/runtime-core/__tests__/apiCreateApp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
15 changes: 8 additions & 7 deletions packages/runtime-core/src/componentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 if (!hasOwn(to, key)) {
} else {
to[key] = from[key]
}
}
const { mixins, extends: extendsOptions } = from

extendsOptions && mergeOptions(to, extendsOptions, instance)
mixins &&
mixins.forEach((m: ComponentOptionsMixin) => mergeOptions(to, m, instance))
}

0 comments on commit 95c07d8

Please sign in to comment.