@@ -47,6 +47,32 @@ module.exports = {
47
47
&& indexParamNames . indexOf ( node . name ) !== - 1 ;
48
48
}
49
49
50
+ function isUsingReactChildren ( node ) {
51
+ const callee = node . callee ;
52
+ if (
53
+ ! callee
54
+ || ! callee . property
55
+ || ! callee . object
56
+ ) {
57
+ return null ;
58
+ }
59
+
60
+ const isReactChildMethod = [ 'map' , 'forEach' ] . indexOf ( callee . property . name ) > - 1 ;
61
+ if ( ! isReactChildMethod ) {
62
+ return null ;
63
+ }
64
+
65
+ const obj = callee . object ;
66
+ if ( obj && obj . name === 'Children' ) {
67
+ return true ;
68
+ }
69
+ if ( obj && obj . object && obj . object . name === 'React' ) {
70
+ return true ;
71
+ }
72
+
73
+ return false ;
74
+ }
75
+
50
76
function getMapIndexParamName ( node ) {
51
77
const callee = node . callee ;
52
78
if ( callee . type !== 'MemberExpression' ) {
@@ -59,16 +85,19 @@ module.exports = {
59
85
return null ;
60
86
}
61
87
62
- const firstArg = node . arguments [ 0 ] ;
63
- if ( ! firstArg ) {
88
+ const callbackArg = isUsingReactChildren ( node )
89
+ ? node . arguments [ 1 ]
90
+ : node . arguments [ 0 ] ;
91
+
92
+ if ( ! callbackArg ) {
64
93
return null ;
65
94
}
66
95
67
- if ( ! astUtil . isFunctionLikeExpression ( firstArg ) ) {
96
+ if ( ! astUtil . isFunctionLikeExpression ( callbackArg ) ) {
68
97
return null ;
69
98
}
70
99
71
- const params = firstArg . params ;
100
+ const params = callbackArg . params ;
72
101
73
102
const indexParamPosition = iteratorFunctionsToIndexParamPosition [ callee . property . name ] ;
74
103
if ( params . length < indexParamPosition + 1 ) {
@@ -132,24 +161,20 @@ module.exports = {
132
161
&& [ 'createElement' , 'cloneElement' ] . indexOf ( node . callee . property . name ) !== - 1
133
162
&& node . arguments . length > 1
134
163
) {
135
- // React.createElement
136
164
if ( ! indexParamNames . length ) {
137
165
return ;
138
166
}
139
-
140
167
const props = node . arguments [ 1 ] ;
141
168
142
169
if ( props . type !== 'ObjectExpression' ) {
143
170
return ;
144
171
}
145
-
146
172
props . properties . forEach ( prop => {
147
173
if ( ! prop . key || prop . key . name !== 'key' ) {
148
174
// { ...foo }
149
175
// { foo: bar }
150
176
return ;
151
177
}
152
-
153
178
checkPropValue ( prop . value ) ;
154
179
} ) ;
155
180
0 commit comments