File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
test/unit/features/options Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ import {
2121 noop
2222} from '../util/index'
2323
24+ import BuiltinVue from '../index'
25+
2426export function initState ( vm : Component ) {
2527 vm . _watchers = [ ]
2628 initProps ( vm )
@@ -143,12 +145,16 @@ function initMethods (vm: Component) {
143145 if ( methods ) {
144146 for ( const key in methods ) {
145147 vm [ key ] = methods [ key ] == null ? noop : bind ( methods [ key ] , vm )
146- if ( process . env . NODE_ENV !== 'production' && methods [ key ] == null ) {
147- warn (
148+ if ( process . env . NODE_ENV !== 'production' ) {
149+ methods [ key ] == null && warn (
148150 `method "${ key } " has an undefined value in the component definition. ` +
149151 `Did you reference the function correctly?` ,
150152 vm
151153 )
154+ hasOwn ( BuiltinVue . prototype , key ) && warn (
155+ `Avoid overriding Vue's internal method "${ key } ".` ,
156+ vm
157+ )
152158 }
153159 }
154160 }
Original file line number Diff line number Diff line change @@ -24,4 +24,14 @@ describe('Options methods', () => {
2424 } )
2525 expect ( `method "hello" has an undefined value in the component definition` ) . toHaveBeenWarned ( )
2626 } )
27+
28+ it ( 'should warn overriding builtin methods' , ( ) => {
29+ new Vue ( {
30+ methods : {
31+ $emit ( ) {
32+ }
33+ }
34+ } )
35+ expect ( `Avoid overriding Vue's internal method "$emit".` ) . toHaveBeenWarned ( )
36+ } )
2737} )
You can’t perform that action at this time.
0 commit comments