File tree Expand file tree Collapse file tree 3 files changed +32
-3
lines changed Expand file tree Collapse file tree 3 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,16 @@ export function checkComponentAttr (el, options) {
4646 if ( is ) {
4747 return is
4848 } else if ( process . env . NODE_ENV !== 'production' ) {
49- if ( isUnknownElement ( el , tag ) ) {
49+ var expectedTag =
50+ options . _componentNameMap &&
51+ options . _componentNameMap [ tag ]
52+ if ( expectedTag ) {
53+ warn (
54+ 'Unknown custom element: <' + tag + '> - ' +
55+ 'did you mean <' + expectedTag + '>? ' +
56+ 'HTML is case-insensitive, remember to use kebab-case in templates!'
57+ )
58+ } else if ( isUnknownElement ( el , tag ) ) {
5059 warn (
5160 'Unknown custom element: <' + tag + '> - did you ' +
5261 'register the component correctly? For recursive components, ' +
Original file line number Diff line number Diff line change 77 isArray ,
88 isPlainObject ,
99 hasOwn ,
10- camelize
10+ camelize ,
11+ hyphenate
1112} from './lang'
1213import { warn } from './debug'
1314import { commonTagRE , reservedTagRE } from './component'
@@ -230,8 +231,11 @@ function guardComponents (options) {
230231 if ( options . components ) {
231232 var components = options . components =
232233 guardArrayAssets ( options . components )
233- var def
234234 var ids = Object . keys ( components )
235+ var def
236+ if ( process . env . NODE_ENV !== 'production' ) {
237+ var map = options . _componentNameMap = { }
238+ }
235239 for ( var i = 0 , l = ids . length ; i < l ; i ++ ) {
236240 var key = ids [ i ]
237241 if ( commonTagRE . test ( key ) || reservedTagRE . test ( key ) ) {
@@ -241,6 +245,11 @@ function guardComponents (options) {
241245 )
242246 continue
243247 }
248+ // record a all lowercase <-> kebab-case mapping for
249+ // possible custom element case error warning
250+ if ( process . env . NODE_ENV !== 'production' ) {
251+ map [ key . replace ( / - / g, '' ) . toLowerCase ( ) ] = hyphenate ( key )
252+ }
244253 def = components [ key ]
245254 if ( isPlainObject ( def ) ) {
246255 components [ key ] = Vue . extend ( def )
Original file line number Diff line number Diff line change @@ -473,4 +473,15 @@ describe('Misc', function () {
473473 } )
474474 expect ( vm . $el . textContent ) . toBe ( 'default content slot1' )
475475 } )
476+
477+ it ( 'warn possible camelCase components' , function ( ) {
478+ new Vue ( {
479+ el : document . createElement ( 'div' ) ,
480+ template : '<HelloWorld></HelloWorld>' ,
481+ components : {
482+ 'hello-world' : { }
483+ }
484+ } )
485+ expect ( hasWarned ( 'did you mean <hello-world>?' ) ) . toBe ( true )
486+ } )
476487} )
You can’t perform that action at this time.
0 commit comments