22
33import { warn , makeMap } from '../util/index'
44
5- let hasProxy , proxyHandlers , initProxy
5+ let initProxy
66
77if ( process . env . NODE_ENV !== 'production' ) {
88 const allowedGlobals = makeMap (
@@ -21,20 +21,22 @@ if (process.env.NODE_ENV !== 'production') {
2121 )
2222 }
2323
24- hasProxy =
24+ const hasProxy =
2525 typeof Proxy !== 'undefined' &&
2626 Proxy . toString ( ) . match ( / n a t i v e c o d e / )
2727
28- proxyHandlers = {
28+ const hasHandler = {
2929 has ( target , key ) {
3030 const has = key in target
3131 const isAllowed = allowedGlobals ( key ) || key . charAt ( 0 ) === '_'
3232 if ( ! has && ! isAllowed ) {
3333 warnNonPresent ( target , key )
3434 }
3535 return has || ! isAllowed
36- } ,
36+ }
37+ }
3738
39+ const getHandler = {
3840 get ( target , key ) {
3941 if ( typeof key === 'string' && ! ( key in target ) ) {
4042 warnNonPresent ( target , key )
@@ -45,7 +47,16 @@ if (process.env.NODE_ENV !== 'production') {
4547
4648 initProxy = function initProxy ( vm ) {
4749 if ( hasProxy ) {
48- vm . _renderProxy = new Proxy ( vm , proxyHandlers )
50+ // determine which proxy handler to use
51+ let handlers
52+ const options = vm . $options
53+ if ( options . template || options . el ) {
54+ handlers = hasHandler
55+ }
56+ if ( options . render ) {
57+ handlers = options . render . _withStripped ? getHandler : hasHandler
58+ }
59+ vm . _renderProxy = handlers ? new Proxy ( vm , handlers ) : vm
4960 } else {
5061 vm . _renderProxy = vm
5162 }
0 commit comments