File tree Expand file tree Collapse file tree 3 files changed +24
-25
lines changed Expand file tree Collapse file tree 3 files changed +24
-25
lines changed Original file line number Diff line number Diff line change 11/* @flow */
22
3- import config from '../config'
43import { ASSET_TYPES } from 'shared/constants'
5- import { warn , isPlainObject } from '../util/index'
4+ import { isPlainObject , validateComponentName } from '../util/index'
65
76export function initAssetRegisters ( Vue : GlobalAPI ) {
87 /**
@@ -17,13 +16,8 @@ export function initAssetRegisters (Vue: GlobalAPI) {
1716 return this . options [ type + 's' ] [ id ]
1817 } else {
1918 /* 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 )
2721 }
2822 if ( type === 'component' && isPlainObject ( definition ) ) {
2923 definition . name = definition . name || id
Original file line number Diff line number Diff line change 11/* @flow */
22
33import { ASSET_TYPES } from 'shared/constants'
4- import { warn , extend , mergeOptions } from '../util/index'
54import { defineComputed , proxy } from '../instance/state'
5+ import { extend , mergeOptions , validateComponentName } from '../util/index'
66
77export function initExtend ( Vue : GlobalAPI ) {
88 /**
@@ -26,14 +26,8 @@ export function initExtend (Vue: GlobalAPI) {
2626 }
2727
2828 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 )
3731 }
3832
3933 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 {
248248 */
249249function checkComponents ( options : Object ) {
250250 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+ )
258269 }
259270}
260271
You can’t perform that action at this time.
0 commit comments