From 2afa2601e05b51569d8d517624ffe0aa5e53a26a Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 12 Dec 2016 21:30:36 -0500 Subject: [PATCH] ensure local assets is prioritized regardless of naming convention (fix #4434) --- src/core/util/options.js | 13 ++++++++----- test/unit/features/global-api/assets.spec.js | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/core/util/options.js b/src/core/util/options.js index 7981d11e..c3f0d3c5 100644 --- a/src/core/util/options.js +++ b/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, diff --git a/test/unit/features/global-api/assets.spec.js b/test/unit/features/global-api/assets.spec.js index e0095025..41e6b5fa 100644 --- a/test/unit/features/global-api/assets.spec.js +++ b/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: 'global' + }) + const vm = new Vue({ + components: { + xFoo: { + template: 'local' + } + }, + template: '
' + }).$mount() + expect(vm.$el.textContent).toBe('local') + delete Vue.options.components['x-foo'] + }) })