@@ -16,6 +16,28 @@ import getFlowType from '../utils/getFlowType';
16
16
import getPropertyName from '../utils/getPropertyName' ;
17
17
import getFlowTypeFromReactComponent from '../utils/getFlowTypeFromReactComponent' ;
18
18
19
+ function setPropDescriptor ( documentation : Documentation , path : NodePath ) : void {
20
+ const propDescriptor = documentation . getPropDescriptor ( getPropertyName ( path ) ) ;
21
+ const type = getFlowType ( path . get ( 'value' ) ) ;
22
+
23
+ if ( type ) {
24
+ propDescriptor . flowType = type ;
25
+ propDescriptor . required = ! path . node . optional ;
26
+ }
27
+ }
28
+
29
+ function findAndSetTypes ( documentation : Documentation , path : NodePath ) : void {
30
+ if ( path . node . properties ) {
31
+ path . get ( 'properties' ) . each (
32
+ propertyPath => setPropDescriptor ( documentation , propertyPath )
33
+ ) ;
34
+ } else if ( path . node . types ) {
35
+ path . get ( 'types' ) . each (
36
+ typesPath => findAndSetTypes ( documentation , typesPath )
37
+ ) ;
38
+ }
39
+ }
40
+
19
41
/**
20
42
* This handler tries to find flow Type annotated react components and extract
21
43
* its types to the documentation. It also extracts docblock comments which are
@@ -28,16 +50,5 @@ export default function flowTypeHandler(documentation: Documentation, path: Node
28
50
return ;
29
51
}
30
52
31
- flowTypesPath . get ( 'properties' ) . each ( propertyPath => {
32
- const propDescriptor = documentation . getPropDescriptor (
33
- getPropertyName ( propertyPath )
34
- ) ;
35
- const valuePath = propertyPath . get ( 'value' ) ;
36
- const type = getFlowType ( valuePath ) ;
37
-
38
- if ( type ) {
39
- propDescriptor . flowType = type ;
40
- propDescriptor . required = ! propertyPath . node . optional ;
41
- }
42
- } ) ;
53
+ findAndSetTypes ( documentation , flowTypesPath ) ;
43
54
}
0 commit comments