Skip to content

Commit d7b55c4

Browse files
committed
detect possible camelCase components
1 parent 95c5dde commit d7b55c4

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/util/component.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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, ' +

src/util/options.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
isArray,
88
isPlainObject,
99
hasOwn,
10-
camelize
10+
camelize,
11+
hyphenate
1112
} from './lang'
1213
import { warn } from './debug'
1314
import { 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)

test/unit/specs/misc_spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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
})

0 commit comments

Comments
 (0)