6
6
binaryExpression ,
7
7
stringLiteral ,
8
8
logicalExpression ,
9
- identifier
9
+ identifier ,
10
+ isJSXSpreadAttribute
10
11
} from '@babel/types' ;
11
12
import optionsDefaults from './schemas/optionsDefaults' ;
12
13
@@ -29,43 +30,44 @@ const createSpreadMapper = (path: *, stats: *): { [destinationName: string]: Exp
29
30
return pair [ 0 ] ;
30
31
} ) ;
31
32
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
+ } ) ;
35
37
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 ] ;
38
41
39
- if ( result [ destinationName ] ) {
40
- result [ destinationName ] = binaryExpression (
42
+ if ( result [ destinationName ] ) {
43
+ result [ destinationName ] = binaryExpression (
44
+ '+' ,
45
+ result [ destinationName ] ,
46
+ binaryExpression (
41
47
'+' ,
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
+ ) ;
66
68
}
67
69
}
68
- } ) ;
70
+ }
69
71
70
72
return result ;
71
73
} ;
0 commit comments