File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed
test/unit/features/global-api Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -319,11 +319,14 @@ export function resolveAsset (
319319 return
320320 }
321321 const assets = options [ type ]
322- const res = assets [ id ] ||
323- // camelCase ID
324- assets [ camelize ( id ) ] ||
325- // Pascal Case ID
326- assets [ capitalize ( camelize ( id ) ) ]
322+ // check local registration variations first
323+ if ( hasOwn ( assets , id ) ) return assets [ id ]
324+ const camelizedId = camelize ( id )
325+ if ( hasOwn ( assets , camelizedId ) ) return assets [ camelizedId ]
326+ const PascalCaseId = capitalize ( camelizedId )
327+ if ( hasOwn ( assets , PascalCaseId ) ) return assets [ PascalCaseId ]
328+ // fallback to prototype chain
329+ const res = assets [ id ] || assets [ camelizedId ] || assets [ PascalCaseId ]
327330 if ( process . env . NODE_ENV !== 'production' && warnMissing && ! res ) {
328331 warn (
329332 'Failed to resolve ' + type . slice ( 0 , - 1 ) + ': ' + id ,
Original file line number Diff line number Diff line change @@ -48,4 +48,21 @@ describe('Global API: assets', () => {
4848 // extended registration should not pollute global
4949 expect ( Vue . options . components . test ) . toBeUndefined ( )
5050 } )
51+
52+ // #4434
53+ it ( 'local registration should take priority regardless of naming convention' , ( ) => {
54+ Vue . component ( 'x-foo' , {
55+ template : '<span>global</span>'
56+ } )
57+ const vm = new Vue ( {
58+ components : {
59+ xFoo : {
60+ template : '<span>local</span>'
61+ }
62+ } ,
63+ template : '<div><x-foo></x-foo></div>'
64+ } ) . $mount ( )
65+ expect ( vm . $el . textContent ) . toBe ( 'local' )
66+ delete Vue . options . components [ 'x-foo' ]
67+ } )
5168} )
You can’t perform that action at this time.
0 commit comments