|
10 | 10 | *
|
11 | 11 | */
|
12 | 12 |
|
13 |
| -import getPropertyName from './getPropertyName'; |
14 | 13 | import getTypeAnnotation from '../utils/getTypeAnnotation';
|
15 | 14 | import getMemberValuePath from '../utils/getMemberValuePath';
|
16 | 15 | import isReactComponentClass from '../utils/isReactComponentClass';
|
@@ -51,7 +50,48 @@ export default (path: NodePath): ?NodePath => {
|
51 | 50 | if (typePath && types.GenericTypeAnnotation.check(typePath.node)) {
|
52 | 51 | typePath = resolveToValue(typePath.get('id'));
|
53 | 52 | if (
|
54 |
| - !typePath || |
| 53 | + !typePath || |
| 54 | + types.Identifier.check(typePath.node) || |
| 55 | + isUnreachableFlowType(typePath) |
| 56 | + ) { |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + typePath = typePath.get('right'); |
| 61 | + } |
| 62 | + |
| 63 | + return typePath; |
| 64 | +} |
| 65 | + |
| 66 | +export function applyToFlowTypeProperties( |
| 67 | + path: NodePath, |
| 68 | + callback: (propertyPath: NodePath) => void |
| 69 | +) { |
| 70 | + if (path.node.properties) { |
| 71 | + path.get('properties').each( |
| 72 | + propertyPath => callback(propertyPath) |
| 73 | + ); |
| 74 | + } else if (path.node.type === 'IntersectionTypeAnnotation') { |
| 75 | + path.get('types').each( |
| 76 | + typesPath => applyToFlowTypeProperties(typesPath, callback) |
| 77 | + ); |
| 78 | + } else if (path.node.type !== 'UnionTypeAnnotation') { |
| 79 | + // The react-docgen output format does not currently allow |
| 80 | + // for the expression of union types |
| 81 | + let typePath = resolveGenericTypeAnnotation(path); |
| 82 | + if (typePath) { |
| 83 | + applyToFlowTypeProperties(typePath, callback); |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +function resolveGenericTypeAnnotation(path: NodePath): ?NodePath { |
| 89 | + // If the node doesn't have types or properties, try to get the type. |
| 90 | + let typePath: ?NodePath; |
| 91 | + if (path && types.GenericTypeAnnotation.check(path.node)) { |
| 92 | + typePath = resolveToValue(path.get('id')); |
| 93 | + if ( |
| 94 | + !typePath || |
55 | 95 | types.Identifier.check(typePath.node) ||
|
56 | 96 | isUnreachableFlowType(typePath)
|
57 | 97 | ) {
|
|
0 commit comments