66 binaryExpression ,
77 stringLiteral ,
88 logicalExpression ,
9- identifier
9+ identifier ,
10+ isJSXSpreadAttribute
1011} from '@babel/types' ;
1112import optionsDefaults from './schemas/optionsDefaults' ;
1213
@@ -29,43 +30,44 @@ const createSpreadMapper = (path: *, stats: *): { [destinationName: string]: Exp
2930 return pair [ 0 ] ;
3031 } ) ;
3132
32- path . traverse ( {
33- JSXSpreadAttribute ( spreadPath : * ) {
34- const spread = spreadPath . node ;
33+ const spreadAttributes = path . node . openingElement . attributes
34+ . filter ( ( attr ) => {
35+ return isJSXSpreadAttribute ( attr ) ;
36+ } ) ;
3537
36- for ( const attributeKey of attributeKeys ) {
37- const destinationName = attributeNames [ attributeKey ] ;
38+ for ( const spread of spreadAttributes ) {
39+ for ( const attributeKey of attributeKeys ) {
40+ const destinationName = attributeNames [ attributeKey ] ;
3841
39- if ( result [ destinationName ] ) {
40- result [ destinationName ] = binaryExpression (
42+ if ( result [ destinationName ] ) {
43+ result [ destinationName ] = binaryExpression (
44+ '+' ,
45+ result [ destinationName ] ,
46+ binaryExpression (
4147 '+' ,
42- result [ destinationName ] ,
43- binaryExpression (
44- '+' ,
45- stringLiteral ( ' ' ) ,
46- logicalExpression (
47- '||' ,
48- memberExpression (
49- spread . argument ,
50- identifier ( destinationName ) ,
51- ) ,
52- stringLiteral ( '' )
53- )
54- ) ,
55- ) ;
56- } else {
57- result [ destinationName ] = logicalExpression (
58- '||' ,
59- memberExpression (
60- spread . argument ,
61- identifier ( destinationName ) ,
62- ) ,
63- stringLiteral ( '' )
64- ) ;
65- }
48+ stringLiteral ( ' ' ) ,
49+ logicalExpression (
50+ '||' ,
51+ memberExpression (
52+ spread . argument ,
53+ identifier ( destinationName ) ,
54+ ) ,
55+ stringLiteral ( '' )
56+ )
57+ ) ,
58+ ) ;
59+ } else {
60+ result [ destinationName ] = logicalExpression (
61+ '||' ,
62+ memberExpression (
63+ spread . argument ,
64+ identifier ( destinationName ) ,
65+ ) ,
66+ stringLiteral ( '' )
67+ ) ;
6668 }
6769 }
68- } ) ;
70+ }
6971
7072 return result ;
7173} ;
0 commit comments