Browse Source

ensure local assets is prioritized regardless of naming convention (fix #4434)

dev
Evan You 8 years ago
parent
commit
2afa2601e0
  1. 13
      src/core/util/options.js
  2. 17
      test/unit/features/global-api/assets.spec.js

13
src/core/util/options.js

@ -319,11 +319,14 @@ export function resolveAsset (
return
}
const assets = options[type]
const res = assets[id] ||
// camelCase ID
assets[camelize(id)] ||
// Pascal Case ID
assets[capitalize(camelize(id))]
// check local registration variations first
if (hasOwn(assets, id)) return assets[id]
const camelizedId = camelize(id)
if (hasOwn(assets, camelizedId)) return assets[camelizedId]
const PascalCaseId = capitalize(camelizedId)
if (hasOwn(assets, PascalCaseId)) return assets[PascalCaseId]
// fallback to prototype chain
const res = assets[id] || assets[camelizedId] || assets[PascalCaseId]
if (process.env.NODE_ENV !== 'production' && warnMissing && !res) {
warn(
'Failed to resolve ' + type.slice(0, -1) + ': ' + id,

17
test/unit/features/global-api/assets.spec.js

@ -48,4 +48,21 @@ describe('Global API: assets', () => {
// extended registration should not pollute global
expect(Vue.options.components.test).toBeUndefined()
})
// #4434
it('local registration should take priority regardless of naming convention', () => {
Vue.component('x-foo', {
template: '<span>global</span>'
})
const vm = new Vue({
components: {
xFoo: {
template: '<span>local</span>'
}
},
template: '<div><x-foo></x-foo></div>'
}).$mount()
expect(vm.$el.textContent).toBe('local')
delete Vue.options.components['x-foo']
})
})

Loading…
Cancel
Save