File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,8 @@ import {
18
18
removeNativeOn ,
19
19
removeOn ,
20
20
checkKeyIsRef ,
21
- checkKeyIsRefInFor
21
+ checkKeyIsRefInFor ,
22
+ checkKeyIsAttrs
22
23
} from './utils'
23
24
import { dealWithDirective } from './directives'
24
25
import { ConfigType , TagType } from './type'
@@ -56,6 +57,15 @@ const jsx = function (
56
57
57
58
const attrKeys = Object . keys ( config )
58
59
for ( let key of attrKeys ) {
60
+ // attrs
61
+ if ( checkKeyIsAttrs ( key ) ) {
62
+ Object . keys ( config [ key ] ) . forEach ( k => {
63
+ config [ k ] = config [ key ] [ k ]
64
+ attrKeys . push ( k )
65
+ } )
66
+ continue
67
+ }
68
+
59
69
// Children shouldn't be set in vNodeData.
60
70
if ( checkKeyIsChildren ( key ) ) {
61
71
continue
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ const checkKeyIsNativeOn = (key: string) => NATIVE_ON_REGEXP.test(key)
45
45
const checkKeyIsVueDirective = ( key : string ) => VUE_DIRECTIVE_REGEXP . test ( key )
46
46
const checkKeyIsRef = ( key : string ) => key === 'ref'
47
47
const checkKeyIsRefInFor = ( key : string ) => key === 'refInFor'
48
+ const checkKeyIsAttrs = ( key : string ) => key === 'attrs'
48
49
49
50
// The reason why I don't use "isRef" which is provided by @vue/composition-api is that
50
51
// this function will be broken under SWC.
@@ -117,6 +118,7 @@ export {
117
118
checkKeyIsRef ,
118
119
checkIsRefObj ,
119
120
checkKeyIsRefInFor ,
121
+ checkKeyIsAttrs ,
120
122
121
123
checkKeyIsVueDirective ,
122
124
Original file line number Diff line number Diff line change @@ -62,6 +62,22 @@ describe('HTML testing.', () => {
62
62
63
63
const wrapper = shallowMount ( Comp )
64
64
} )
65
+
66
+ it ( 'Should support attr spread operator.' , ( ) => {
67
+ const wrapper = shallowMount ( {
68
+ setup ( ) {
69
+ const attrs = {
70
+ type : 'email' ,
71
+ placeholder : 'Enter your email'
72
+ }
73
+
74
+ return ( ) => (
75
+ < input { ...{ attrs } } />
76
+ )
77
+ }
78
+ } )
79
+ expect ( wrapper . html ( ) ) . toBe ( '<input type="email" placeholder="Enter your email">' )
80
+ } )
65
81
} )
66
82
67
83
describe ( 'Vue component testing.' , ( ) => {
You can’t perform that action at this time.
0 commit comments