File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,12 @@ export default function (Vue) {
71
71
return extendOptions . _Ctor
72
72
}
73
73
var name = extendOptions . name || Super . options . name
74
+ if ( process . env . NODE_ENV !== 'production' ) {
75
+ if ( ! / ^ [ a - z A - Z ] [ \w - ] + $ / . test ( name ) ) {
76
+ warn ( 'Invalid component name: ' + name )
77
+ name = null
78
+ }
79
+ }
74
80
var Sub = createClass ( name || 'VueComponent' )
75
81
Sub . prototype = Object . create ( Super . prototype )
76
82
Sub . prototype . constructor = Sub
Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ var config = require('../../../../src/config')
4
4
5
5
describe ( 'Global API' , function ( ) {
6
6
7
+ beforeEach ( function ( ) {
8
+ spyWarns ( )
9
+ } )
10
+
7
11
it ( 'exposed utilities' , function ( ) {
8
12
expect ( Vue . util ) . toBe ( _ )
9
13
expect ( Vue . nextTick ) . toBe ( _ . nextTick )
@@ -39,6 +43,15 @@ describe('Global API', function () {
39
43
expect ( t2 . $options . b ) . toBe ( 2 )
40
44
} )
41
45
46
+ it ( 'extend warn invalid names' , function ( ) {
47
+ Vue . extend ( { name : '123' } )
48
+ expect ( hasWarned ( 'Invalid component name: 123' ) ) . toBe ( true )
49
+ Vue . extend ( { name : '_fesf' } )
50
+ expect ( hasWarned ( 'Invalid component name: _fesf' ) ) . toBe ( true )
51
+ Vue . extend ( { name : 'Some App' } )
52
+ expect ( hasWarned ( 'Invalid component name: Some App' ) ) . toBe ( true )
53
+ } )
54
+
42
55
it ( 'use' , function ( ) {
43
56
var def = { }
44
57
var options = { }
You can’t perform that action at this time.
0 commit comments