Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 591e79f

Browse filesBrowse files
committed
improve component name warning
1 parent b00dbca commit 591e79f
Copy full SHA for 591e79f

File tree

Expand file treeCollapse file tree

2 files changed

+8
-5
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+8
-5
lines changed

‎src/instance/api/global.js

Copy file name to clipboardExpand all lines: src/instance/api/global.js
+5-2Lines 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

Copy file name to clipboardExpand all lines: test/unit/specs/api/global_spec.js
+3-3Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.