@@ -163,23 +163,46 @@ module.exports = {
163
163
} ) ) ;
164
164
}
165
165
166
+ /**
167
+ * Handles Props defined in IntersectionTypeAnnotation nodes
168
+ * e.g. type Props = PropsA & PropsB
169
+ * @param {ASTNode } intersectionTypeAnnotation ObjectExpression node.
170
+ * @returns {Object[] }
171
+ */
172
+ function getPropertiesFromIntersectionTypeAnnotationNode ( annotation ) {
173
+ return annotation . types . reduce ( ( properties , type ) => {
174
+ annotation = resolveGenericTypeAnnotation ( type ) ;
175
+
176
+ if ( annotation && annotation . id ) {
177
+ annotation = findVariableByName ( annotation . id . name ) ;
178
+ }
179
+
180
+ return properties . concat ( annotation . properties ) ;
181
+ } , [ ] ) ;
182
+ }
183
+
166
184
/**
167
185
* Extracts a PropType from a TypeAnnotation node.
168
186
* @param {ASTNode } node TypeAnnotation node.
169
187
* @returns {Object[] } Array of PropType object representations, to be consumed by `addPropTypesToComponent`.
170
188
*/
171
189
function getPropTypesFromTypeAnnotation ( node ) {
172
- let properties ;
190
+ let properties = [ ] ;
173
191
174
192
switch ( node . typeAnnotation . type ) {
175
193
case 'GenericTypeAnnotation' :
176
194
let annotation = resolveGenericTypeAnnotation ( node . typeAnnotation ) ;
177
195
178
- if ( annotation && annotation . id ) {
179
- annotation = findVariableByName ( annotation . id . name ) ;
196
+ if ( annotation && annotation . type === 'IntersectionTypeAnnotation' ) {
197
+ properties = getPropertiesFromIntersectionTypeAnnotationNode ( annotation ) ;
198
+ } else {
199
+ if ( annotation && annotation . id ) {
200
+ annotation = findVariableByName ( annotation . id . name ) ;
201
+ }
202
+
203
+ properties = annotation ? ( annotation . properties || [ ] ) : [ ] ;
180
204
}
181
205
182
- properties = annotation ? ( annotation . properties || [ ] ) : [ ] ;
183
206
break ;
184
207
185
208
case 'UnionTypeAnnotation' :
@@ -314,7 +337,6 @@ module.exports = {
314
337
if ( ! component ) {
315
338
return ;
316
339
}
317
-
318
340
addPropTypesToComponent ( component , getPropTypesFromTypeAnnotation ( node . typeAnnotation , context ) ) ;
319
341
}
320
342
0 commit comments