@@ -1004,36 +1004,28 @@ export function finishComponentSetup(
10041004 }
10051005}
10061006
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+ }
10371029
10381030/**
10391031 * Dev-only
@@ -1080,9 +1072,13 @@ export function createSetupContext(
10801072 if ( __DEV__ ) {
10811073 // We use getters in dev in case libs like test-utils overwrite instance
10821074 // properties (overwrites should not be done in prod)
1075+ let attrsProxy : Data
10831076 return Object . freeze ( {
10841077 get attrs ( ) {
1085- return getAttrsProxy ( instance )
1078+ return (
1079+ attrsProxy ||
1080+ ( attrsProxy = new Proxy ( instance . attrs , attrsProxyHandlers ) )
1081+ )
10861082 } ,
10871083 get slots ( ) {
10881084 return getSlotsProxy ( instance )
@@ -1094,9 +1090,7 @@ export function createSetupContext(
10941090 } )
10951091 } else {
10961092 return {
1097- get attrs ( ) {
1098- return getAttrsProxy ( instance )
1099- } ,
1093+ attrs : new Proxy ( instance . attrs , attrsProxyHandlers ) ,
11001094 slots : instance . slots ,
11011095 emit : instance . emit ,
11021096 expose,
0 commit comments