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 {
1818 removeNativeOn ,
1919 removeOn ,
2020 checkKeyIsRef ,
21- checkKeyIsRefInFor
21+ checkKeyIsRefInFor ,
22+ checkKeyIsAttrs
2223} from './utils'
2324import { dealWithDirective } from './directives'
2425import { ConfigType , TagType } from './type'
@@ -56,6 +57,15 @@ const jsx = function (
5657
5758 const attrKeys = Object . keys ( config )
5859 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+
5969 // Children shouldn't be set in vNodeData.
6070 if ( checkKeyIsChildren ( key ) ) {
6171 continue
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ const checkKeyIsNativeOn = (key: string) => NATIVE_ON_REGEXP.test(key)
4545const checkKeyIsVueDirective = ( key : string ) => VUE_DIRECTIVE_REGEXP . test ( key )
4646const checkKeyIsRef = ( key : string ) => key === 'ref'
4747const checkKeyIsRefInFor = ( key : string ) => key === 'refInFor'
48+ const checkKeyIsAttrs = ( key : string ) => key === 'attrs'
4849
4950// The reason why I don't use "isRef" which is provided by @vue/composition-api is that
5051// this function will be broken under SWC.
@@ -117,6 +118,7 @@ export {
117118 checkKeyIsRef ,
118119 checkIsRefObj ,
119120 checkKeyIsRefInFor ,
121+ checkKeyIsAttrs ,
120122
121123 checkKeyIsVueDirective ,
122124
Original file line number Diff line number Diff line change @@ -62,6 +62,22 @@ describe('HTML testing.', () => {
6262
6363 const wrapper = shallowMount ( Comp )
6464 } )
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+ } )
6581} )
6682
6783describe ( 'Vue component testing.' , ( ) => {
You can’t perform that action at this time.
0 commit comments