Skip to content

Commit 962b778

Browse files
phananyyx990803
authored andcommitted
More informative warning message for comp name (vuejs#4429)
This commit adds a more informative warning message for invalid component names. Also fixes a typo. Closes vuejs#4428.
1 parent 29d6e33 commit 962b778

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/core/global-api/extend.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export function initExtend (Vue: GlobalAPI) {
2828
if (!/^[a-zA-Z][\w-]*$/.test(name)) {
2929
warn(
3030
'Invalid component name: "' + name + '". Component names ' +
31-
'can only contain alphanumeric characaters and the hyphen.'
31+
'can only contain alphanumeric characters and the hyphen, ' +
32+
'and must start with a letter.'
3233
)
3334
}
3435
}

test/unit/features/options/name.spec.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@ describe('Options name', () => {
1515
})
1616

1717
/* eslint-disable */
18-
expect(`Invalid component name: "Hyper*Vue". Component names can only contain alphanumeric characaters and the hyphen.`)
18+
expect(`Invalid component name: "Hyper*Vue". Component names can only contain alphanumeric characters and the hyphen, and must start with a letter.`)
19+
.toHaveBeenWarned()
20+
/* eslint-enable */
21+
22+
Vue.extend({
23+
name: '2Cool2BValid'
24+
})
25+
26+
/* eslint-disable */
27+
expect(`Invalid component name: "2Cool2BValid". Component names can only contain alphanumeric characters and the hyphen, and must start with a letter.`)
1928
.toHaveBeenWarned()
2029
/* eslint-enable */
2130
})

0 commit comments

Comments
 (0)