More informative warning message for comp name (#4429)

This commit adds a more informative warning message for invalid
component names. Also fixes a typo.
Closes #4428.
This commit is contained in:
Phan An 2016-12-10 01:51:13 +08:00 committed by Evan You
parent 29d6e33b33
commit 962b778e10
2 changed files with 12 additions and 2 deletions

View File

@ -28,7 +28,8 @@ export function initExtend (Vue: GlobalAPI) {
if (!/^[a-zA-Z][\w-]*$/.test(name)) {
warn(
'Invalid component name: "' + name + '". Component names ' +
'can only contain alphanumeric characaters and the hyphen.'
'can only contain alphanumeric characters and the hyphen, ' +
'and must start with a letter.'
)
}
}

View File

@ -15,7 +15,16 @@ describe('Options name', () => {
})
/* eslint-disable */
expect(`Invalid component name: "Hyper*Vue". Component names can only contain alphanumeric characaters and the hyphen.`)
expect(`Invalid component name: "Hyper*Vue". Component names can only contain alphanumeric characters and the hyphen, and must start with a letter.`)
.toHaveBeenWarned()
/* eslint-enable */
Vue.extend({
name: '2Cool2BValid'
})
/* eslint-disable */
expect(`Invalid component name: "2Cool2BValid". Component names can only contain alphanumeric characters and the hyphen, and must start with a letter.`)
.toHaveBeenWarned()
/* eslint-enable */
})