File tree 5 files changed +30
-8
lines changed
5 files changed +30
-8
lines changed Original file line number Diff line number Diff line change @@ -504,12 +504,25 @@ const SetupProxyHandlers: { [key: string]: ProxyHandler<any> } = {}
504
504
}
505
505
} )
506
506
507
+ const attrsProxyHandlers : ProxyHandler < Data > = {
508
+ get ( target , key : string ) {
509
+ if ( __DEV__ ) {
510
+ markAttrsAccessed ( )
511
+ }
512
+ return target [ key ]
513
+ } ,
514
+ set : ( ) => false ,
515
+ deleteProperty : ( ) => false
516
+ }
517
+
507
518
function createSetupContext ( instance : ComponentInternalInstance ) : SetupContext {
508
519
const context = {
509
520
// attrs & slots are non-reactive, but they need to always expose
510
521
// the latest values (instance.xxx may get replaced during updates) so we
511
522
// need to expose them through a proxy
512
- attrs : new Proxy ( instance , SetupProxyHandlers . attrs ) ,
523
+ attrs : __DEV__
524
+ ? new Proxy ( instance . attrs , attrsProxyHandlers )
525
+ : instance . attrs ,
513
526
slots : new Proxy ( instance , SetupProxyHandlers . slots ) ,
514
527
get emit ( ) {
515
528
return instance . emit
Original file line number Diff line number Diff line change 5
5
EMPTY_OBJ ,
6
6
capitalize ,
7
7
hyphenate ,
8
- isFunction
8
+ isFunction ,
9
+ def
9
10
} from '@vue/shared'
10
11
import { ComponentInternalInstance } from './component'
11
12
import { callWithAsyncErrorHandling , ErrorCodes } from './errorHandling'
@@ -96,7 +97,7 @@ export function normalizeEmitsOptions(
96
97
}
97
98
const normalized : ObjectEmitsOptions = { }
98
99
options . forEach ( key => ( normalized [ key ] = null ) )
99
- Object . defineProperty ( options , '_n' , { value : normalized } )
100
+ def ( options , '_n' , normalized )
100
101
return normalized
101
102
} else {
102
103
return options
Original file line number Diff line number Diff line change @@ -13,11 +13,13 @@ import {
13
13
PatchFlags ,
14
14
makeMap ,
15
15
isReservedProp ,
16
- EMPTY_ARR
16
+ EMPTY_ARR ,
17
+ def
17
18
} from '@vue/shared'
18
19
import { warn } from './warning'
19
20
import { Data , ComponentInternalInstance } from './component'
20
21
import { isEmitListener } from './componentEmits'
22
+ import { InternalObjectSymbol } from './vnode'
21
23
22
24
export type ComponentPropsOptions < P = Data > =
23
25
| ComponentObjectPropsOptions < P >
@@ -102,6 +104,7 @@ export function initProps(
102
104
) {
103
105
const props : Data = { }
104
106
const attrs : Data = { }
107
+ def ( attrs , InternalObjectSymbol , true )
105
108
setFullProps ( instance , rawProps , props , attrs )
106
109
const options = instance . type . props
107
110
// validation
@@ -310,7 +313,7 @@ export function normalizePropsOptions(
310
313
}
311
314
}
312
315
const normalizedEntry : NormalizedPropsOptions = [ normalized , needCastKeys ]
313
- Object . defineProperty ( raw , '_n' , { value : normalizedEntry } )
316
+ def ( raw , '_n' , normalizedEntry )
314
317
return normalizedEntry
315
318
}
316
319
Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ import {
13
13
import {
14
14
ComponentInternalInstance ,
15
15
Data ,
16
- SetupProxySymbol ,
17
16
Component ,
18
17
ClassComponent
19
18
} from './component'
@@ -235,6 +234,8 @@ const createVNodeWithArgsTransform = (
235
234
)
236
235
}
237
236
237
+ export const InternalObjectSymbol = Symbol ( )
238
+
238
239
export const createVNode = ( __DEV__
239
240
? createVNodeWithArgsTransform
240
241
: _createVNode ) as typeof _createVNode
@@ -261,7 +262,7 @@ function _createVNode(
261
262
// class & style normalization.
262
263
if ( props ) {
263
264
// for reactive or proxy objects, we need to clone it to enable mutation.
264
- if ( isReactive ( props ) || SetupProxySymbol in props ) {
265
+ if ( isReactive ( props ) || InternalObjectSymbol in props ) {
265
266
props = extend ( { } , props )
266
267
}
267
268
let { class : klass , style } = props
Original file line number Diff line number Diff line change @@ -120,8 +120,12 @@ export const toDisplayString = (val: unknown): string => {
120
120
: String ( val )
121
121
}
122
122
123
- export function invokeArrayFns ( fns : Function [ ] , arg ?: any ) {
123
+ export const invokeArrayFns = ( fns : Function [ ] , arg ?: any ) => {
124
124
for ( let i = 0 ; i < fns . length ; i ++ ) {
125
125
fns [ i ] ( arg )
126
126
}
127
127
}
128
+
129
+ export const def = ( obj : object , key : string | symbol , value : any ) => {
130
+ Object . defineProperty ( obj , key , { value } )
131
+ }
You can’t perform that action at this time.
0 commit comments