8000 improve component name warning · mircle/vue@591e79f · GitHub
[go: up one dir, main page]

Skip to content

Commit 591e79f

Browse files
committed
improve component name warning
1 parent b00dbca commit 591e79f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/instance/api/global.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,11 @@ export default function (Vue) {
7373
}
7474
var name = extendOptions.name || Super.options.name
7575
if (process.env.NODE_ENV !== 'production') {
76-
if (!/^[a-zA-Z][\w-]+$/.test(name)) {
77-
warn('Invalid component name: ' + name)
76+
if (!/^[a-zA-Z][\w-]*$/.test(name)) {
77+
warn(
78+
'Invalid component name: "' + name + '". Component names ' +
79+
'can only contain alphanumeric characaters and the hyphen.'
80+
)
7881
name = null
7982
}
8083
}

test/unit/specs/api/global_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ describe('Global API', function () {
4545

4646
it('extend warn invalid names', function () {
4747
Vue.extend({ name: '123' })
48-
expect(hasWarned('Invalid component name: 123')).toBe(true)
48+
expect(hasWarned('Invalid component name: "123"')).toBe(true)
4949
Vue.extend({ name: '_fesf' })
50-
expect(hasWarned('Invalid component name: _fesf')).toBe(true)
50+
expect(hasWarned('Invalid component name: "_fesf"')).toBe(true)
5151
Vue.extend({ name: 'Some App' })
52-
expect(hasWarned('Invalid component name: Some App')).toBe(true)
52+
expect(hasWarned('Invalid component name: "Some App"')).toBe(true)
5353
})
5454

5555
it('use', function () {

0 commit comments

Comments
 (0)
0