@@ -12,39 +12,43 @@ export function patchAttrs(instance: ComponentInternalInstance) {
12
12
propsOptions : [ options ] ,
13
13
} = instance
14
14
15
+ if ( ! rawProps . length ) return
15
16
const keys = new Set < string > ( )
16
- if ( rawProps . length )
17
- for ( const props of Array . from ( rawProps ) . reverse ( ) ) {
18
- if ( isFunction ( props ) ) {
19
- const resolved = props ( )
20
- for ( const rawKey in resolved ) {
21
- registerAttr ( rawKey , ( ) => resolved [ rawKey ] )
22
- }
23
- } else {
24
- for ( const rawKey in props ) {
25
- registerAttr ( rawKey , props [ rawKey ] )
26
- }
17
+ for ( const props of Array . from ( rawProps ) . reverse ( ) ) {
18
+ if ( isFunction ( props ) ) {
19
+ const resolved = props ( )
20
+ for ( const rawKey in resolved ) {
21
+ registerAttr ( rawKey , resolved [ rawKey ] )
22
+ }
23
+ } else {
24
+ for ( const rawKey in props ) {
25
+ registerAttr ( rawKey , props [ rawKey ] , true )
27
26
}
28
27
}
28
+ }
29
29
30
30
for ( const key in attrs ) {
31
31
if ( ! keys . has ( key ) ) {
32
32
delete attrs [ key ]
33
33
}
34
34
}
35
35
36
- function registerAttr ( key : string , getter : ( ) => unknown ) {
36
+ function registerAttr ( key : string , value : any , getter ?: boolean ) {
37
37
if (
38
38
( ! options || ! ( camelize ( key ) in options ) ) &&
39
- ! isEmitListener ( instance . emitsOptions , key )
39
+ ! isEmitListener ( instance . emitsOptions , key ) &&
40
+ ! keys . has ( key )
40
41
) {
41
42
keys . add ( key )
42
- if ( key in attrs ) return
43
- Object . defineProperty ( attrs , key , {
44
- get : getter ,
45
- enumerable : true ,
46
- configurable : true ,
47
- } )
43
+ if ( getter ) {
44
+ Object . defineProperty ( attrs , key , {
45
+ get : value ,
46
+ enumerable : true ,
47
+ configurable : true ,
48
+ } )
49
+ } else {
50
+ attrs [ key ] = value
51
+ }
48
52
}
49
53
}
50
54
}
0 commit comments