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) {
7171 return extendOptions . _Ctor
7272 }
7373 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+ }
7480 var Sub = createClass ( name || 'VueComponent' )
7581 Sub . prototype = Object . create ( Super . prototype )
7682 Sub . prototype . constructor = Sub
Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ var config = require('../../../../src/config')
44
55describe ( 'Global API' , function ( ) {
66
7+ beforeEach ( function ( ) {
8+ spyWarns ( )
9+ } )
10+
711 it ( 'exposed utilities' , function ( ) {
812 expect ( Vue . util ) . toBe ( _ )
913 expect ( Vue . nextTick ) . toBe ( _ . nextTick )
@@ -39,6 +43,15 @@ describe('Global API', function () {
3943 expect ( t2 . $options . b ) . toBe ( 2 )
4044 } )
4145
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+
4255 it ( 'use' , function ( ) {
4356 var def = { }
4457 var options = { }
You can’t perform that action at this time.
0 commit comments