@@ -19,14 +19,27 @@ module.exports = {
19
19
schema : [ ] // no options
20
20
} ,
21
21
create : function ( context ) {
22
+ function findSpreadVariable ( name ) {
23
+ return variableUtil . variablesInScope ( context ) . find ( function ( item ) {
24
+ return item . name === name ;
25
+ } ) ;
26
+ }
22
27
/**
23
28
* Takes a ObjectExpression and returns the value of the prop if it has it
24
29
* @param {object } node - ObjectExpression node
25
30
* @param {string } propName - name of the prop to look for
26
31
*/
27
32
function findObjectProp ( node , propName ) {
28
33
return node . properties . find ( function ( prop ) {
29
- return prop . key . name === propName ;
34
+ if ( prop . type === 'Property' ) {
35
+ return prop . key . name === propName ;
36
+ } else if ( prop . type === 'ExperimentalSpreadProperty' ) {
37
+ var variable = findSpreadVariable ( prop . argument . name ) ;
38
+ if ( variable && variable . defs [ 0 ] . node . init ) {
39
+ return findObjectProp ( variable . defs [ 0 ] . node . init , propName ) ;
40
+ }
41
+ }
42
+ return false ;
30
43
} ) ;
31
44
}
32
45
@@ -39,9 +52,7 @@ module.exports = {
39
52
var attributes = node . openingElement . attributes ;
40
53
return attributes . find ( function ( attribute ) {
41
54
if ( attribute . type === 'JSXSpreadAttribute' ) {
42
- var variable = variableUtil . variablesInScope ( context ) . find ( function ( item ) {
43
- return item . name === attribute . argument . name ;
44
- } ) ;
55
+ var variable = findSpreadVariable ( attribute . argument . name ) ;
45
56
if ( variable && variable . defs [ 0 ] . node . init ) {
46
57
return findObjectProp ( variable . defs [ 0 ] . node . init , propName ) ;
47
58
}
0 commit comments