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) {
46
46
if ( is ) {
47
47
return is
48
48
} 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 ) ) {
50
59
warn (
51
60
'Unknown custom element: <' + tag + '> - did you ' +
52
61
'register the component correctly? For recursive components, ' +
Original file line number Diff line number Diff line change 7
7
isArray ,
8
8
isPlainObject ,
9
9
hasOwn ,
10
- camelize
10
+ camelize ,
11
+ hyphenate
11
12
} from './lang'
12
13
import { warn } from './debug'
13
14
import { commonTagRE , reservedTagRE } from './component'
@@ -230,8 +231,11 @@ function guardComponents (options) {
230
231
if ( options . components ) {
231
232
var components = options . components =
232
233
guardArrayAssets ( options . components )
233
- var def
234
234
var ids = Object . keys ( components )
235
+ var def
236
+ if ( process . env . NODE_ENV !== 'production' ) {
237
+ var map = options . _componentNameMap = { }
238
+ }
235
239
for ( var i = 0 , l = ids . length ; i < l ; i ++ ) {
236
240
var key = ids [ i ]
237
241
if ( commonTagRE . test ( key ) || reservedTagRE . test ( key ) ) {
@@ -241,6 +245,11 @@ function guardComponents (options) {
241
245
)
242
246
continue
243
247
}
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
+ }
244
253
def = components [ key ]
245
254
if ( isPlainObject ( def ) ) {
246
255
components [ key ] = Vue . extend ( def )
Original file line number Diff line number Diff line change @@ -473,4 +473,15 @@ describe('Misc', function () {
473
473
} )
474
474
expect ( vm . $el . textContent ) . toBe ( 'default content slot1' )
475
475
} )
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
+ } )
476
487
} )
You can’t perform that action at this time.
0 commit comments