@@ -1004,36 +1004,28 @@ export function finishComponentSetup(
1004
1004
}
1005
1005
}
1006
1006
1007
- function getAttrsProxy ( instance : ComponentInternalInstance ) : Data {
1008
- return (
1009
- instance . attrsProxy ||
1010
- ( instance . attrsProxy = new Proxy (
1011
- instance . attrs ,
1012
- __DEV__
1013
- ? {
1014
- get ( target , key : string ) {
1015
- markAttrsAccessed ( )
1016
- track ( instance , TrackOpTypes . GET , '$attrs' )
1017
- return target [ key ]
1018
- } ,
1019
- set ( ) {
1020
- warn ( `setupContext.attrs is readonly.` )
1021
- return false
1022
- } ,
1023
- deleteProperty ( ) {
1024
- warn ( `setupContext.attrs is readonly.` )
1025
- return false
1026
- } ,
1027
- }
1028
- : {
1029
- get ( target , key : string ) {
1030
- track ( instance , TrackOpTypes . GET , '$attrs' )
1031
- return target [ key ]
1032
- } ,
1033
- } ,
1034
- ) )
1035
- )
1036
- }
1007
+ const attrsProxyHandlers = __DEV__
1008
+ ? {
1009
+ get ( target : Data , key : string ) {
1010
+ markAttrsAccessed ( )
1011
+ track ( target , TrackOpTypes . GET , '' )
1012
+ return target [ key ]
1013
+ } ,
1014
+ set ( ) {
1015
+ warn ( `setupContext.attrs is readonly.` )
1016
+ return false
1017
+ } ,
1018
+ deleteProperty ( ) {
1019
+ warn ( `setupContext.attrs is readonly.` )
1020
+ return false
1021
+ } ,
1022
+ }
1023
+ : {
1024
+ get ( target : Data , key : string ) {
1025
+ track ( target , TrackOpTypes . GET , '' )
1026
+ return target [ key ]
1027
+ } ,
1028
+ }
1037
1029
1038
1030
/**
1039
1031
* Dev-only
@@ -1080,9 +1072,13 @@ export function createSetupContext(
1080
1072
if ( __DEV__ ) {
1081
1073
// We use getters in dev in case libs like test-utils overwrite instance
1082
1074
// properties (overwrites should not be done in prod)
1075
+ let attrsProxy : Data
1083
1076
return Object . freeze ( {
1084
1077
get attrs ( ) {
1085
- return getAttrsProxy ( instance )
1078
+ return (
1079
+ attrsProxy ||
1080
+ ( attrsProxy = new Proxy ( instance . attrs , attrsProxyHandlers ) )
1081
+ )
1086
1082
} ,
1087
1083
get slots ( ) {
1088
1084
return getSlotsProxy ( instance )
@@ -1094,9 +1090,7 @@ export function createSetupContext(
1094
1090
} )
1095
1091
} else {
1096
1092
return {
1097
- get attrs ( ) {
1098
- return getAttrsProxy ( instance )
1099
- } ,
1093
+ attrs : new Proxy ( instance . attrs , attrsProxyHandlers ) ,
1100
1094
slots : instance . slots ,
1101
1095
emit : instance . emit ,
1102
1096
expose,
0 commit comments