File tree 3 files changed +24
-25
lines changed
3 files changed +24
-25
lines changed Original file line number Diff line number Diff line change 1
1
/* @flow */
2
2
3
- import config from '../config'
4
3
import { ASSET_TYPES } from 'shared/constants'
5
- import { warn , isPlainObject } from '../util/index'
4
+ import { isPlainObject , validateComponentName } from '../util/index'
6
5
7
6
export function initAssetRegisters ( Vue : GlobalAPI ) {
8
7
/**
@@ -17,13 +16,8 @@ export function initAssetRegisters (Vue: GlobalAPI) {
17
16
return this . options [ type + 's' ] [ id ]
18
17
} else {
19
18
/* istanbul ignore if */
20
- if ( process . env . NODE_ENV !== 'production' ) {
21
- if ( type === 'component' && config . isReservedTag ( id ) ) {
22
- warn (
23
- 'Do not use built-in or reserved HTML elements as component ' +
24
- 'id: ' + id
25
- )
26
- }
19
+ if ( process . env . NODE_ENV !== 'production' && type === 'component' ) {
20
+ validateComponentName ( id )
27
21
}
28
22
if ( type === 'component' && isPlainObject ( definition ) ) {
29
23
definition . name = definition . name || id
Original file line number Diff line number Diff line change 1
1
/* @flow */
2
2
3
3
import { ASSET_TYPES } from 'shared/constants'
4
- import { warn , extend , mergeOptions } from '../util/index'
5
4
import { defineComputed , proxy } from '../instance/state'
5
+ import { extend , mergeOptions , validateComponentName } from '../util/index'
6
6
7
7
export function initExtend ( Vue : GlobalAPI ) {
8
8
/**
@@ -26,14 +26,8 @@ export function initExtend (Vue: GlobalAPI) {
26
26
}
27
27
28
28
const name = extendOptions . name || Super . options . name
29
- if ( process . env . NODE_ENV !== 'production' ) {
30
- if ( ! / ^ [ a - z A - Z ] [ \w - ] * $ / . test ( name ) ) {
31
- warn (
32
- 'Invalid component name: "' + name + '". Component names ' +
33
- 'can only contain alphanumeric characters and the hyphen, ' +
34
- 'and must start with a letter.'
35
- )
36
- }
29
+ if ( process . env . NODE_ENV !== 'production' && name ) {
30
+ validateComponentName ( name )
37
31
}
38
32
39
33
const Sub = function VueComponent ( options ) {
Original file line number Diff line number Diff line change @@ -248,13 +248,24 @@ const defaultStrat = function (parentVal: any, childVal: any): any {
248
248
*/
249
249
function checkComponents ( options : Object ) {
250
250
for ( const key in options . components ) {
251
- const lower = key . toLowerCase ( )
252
- if ( isBuiltInTag ( lower ) || config . isReservedTag ( lower ) ) {
253
- warn (
254
- 'Do not use built-in or reserved HTML elements as component ' +
255
- 'id: ' + key
256
- )
257
- }
251
+ validateComponentName ( key )
252
+ }
253
+ }
254
+
255
+ export function validateComponentName ( name : string ) {
256
+ if ( ! / ^ [ a - z A - Z ] [ \w - ] * $ / . test ( name ) ) {
257
+ warn (
258
+ 'Invalid component name: "' + name + '". Component names ' +
259
+ 'can only contain alphanumeric characters and the hyphen, ' +
260
+ 'and must start with a letter.'
261
+ )
262
+ }
263
+ const lower = name . toLowerCase ( )
264
+ if ( isBuiltInTag ( lower ) || config . isReservedTag ( lower ) ) {
265
+ warn (
266
+ 'Do not use built-in or reserved HTML elements as component ' +
267
+ 'id: ' + name
268
+ )
258
269
}
259
270
}
260
271
You can’t perform that action at this time.
0 commit comments