2
2
3
3
import { warn , makeMap } from '../util/index'
4
4
5
- let hasProxy , proxyHandlers , initProxy
5
+ let initProxy
6
6
7
7
if ( process . env . NODE_ENV !== 'production' ) {
8
8
const allowedGlobals = makeMap (
@@ -21,20 +21,22 @@ if (process.env.NODE_ENV !== 'production') {
21
21
)
22
22
}
23
23
24
- hasProxy =
24
+ const hasProxy =
25
25
typeof Proxy !== 'undefined' &&
26
26
Proxy . toString ( ) . match ( / n a t i v e c o d e / )
27
27
28
- proxyHandlers = {
28
+ const hasHandler = {
29
29
has ( target , key ) {
30
30
const has = key in target
31
31
const isAllowed = allowedGlobals ( key ) || key . charAt ( 0 ) === '_'
32
32
if ( ! has && ! isAllowed ) {
33
33
warnNonPresent ( target , key )
34
34
}
35
35
return has || ! isAllowed
36
- } ,
36
+ }
37
+ }
37
38
39
+ const getHandler = {
38
40
get ( target , key ) {
39
41
if ( typeof key === 'string' && ! ( key in target ) ) {
40
42
warnNonPresent ( target , key )
@@ -45,7 +47,16 @@ if (process.env.NODE_ENV !== 'production') {
45
47
46
48
initProxy = function initProxy ( vm ) {
47
49
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
49
60
} else {
50
61
vm . _renderProxy = vm
51
62
}
0 commit comments