|
10 | 10 | import { namedTypes as t } from 'ast-types';
|
11 | 11 | import type Documentation from '../Documentation';
|
12 | 12 | import { getDocblock } from '../utils/docblock';
|
| 13 | +import isReactForwardRefCall from '../utils/isReactForwardRefCall'; |
| 14 | +import resolveToValue from '../utils/resolveToValue'; |
13 | 15 |
|
14 | 16 | function isClassDefinition(nodePath) {
|
15 | 17 | const node = nodePath.node;
|
16 | 18 | return t.ClassDeclaration.check(node) || t.ClassExpression.check(node);
|
17 | 19 | }
|
18 | 20 |
|
19 |
| -/** |
20 |
| - * Finds the nearest block comment before the component definition. |
21 |
| - */ |
22 |
| -export default function componentDocblockHandler( |
23 |
| - documentation: Documentation, |
24 |
| - path: NodePath, |
25 |
| -) { |
| 21 | +function getDocblockFromComponent(path) { |
26 | 22 | let description = null;
|
27 | 23 |
|
28 | 24 | if (isClassDefinition(path)) {
|
@@ -52,5 +48,21 @@ export default function componentDocblockHandler(
|
52 | 48 | description = getDocblock(searchPath);
|
53 | 49 | }
|
54 | 50 | }
|
55 |
| - documentation.set('description', description || ''); |
| 51 | + if (!description && isReactForwardRefCall(path)) { |
| 52 | + const inner = resolveToValue(path.get('arguments', 0)); |
| 53 | + if (inner.node !== path.node) { |
| 54 | + return getDocblockFromComponent(inner); |
| 55 | + } |
| 56 | + } |
| 57 | + return description; |
| 58 | +} |
| 59 | + |
| 60 | +/** |
| 61 | + * Finds the nearest block comment before the component definition. |
| 62 | + */ |
| 63 | +export default function componentDocblockHandler( |
| 64 | + documentation: Documentation, |
| 65 | + path: NodePath, |
| 66 | +) { |
| 67 | + documentation.set('description', getDocblockFromComponent(path) || ''); |
56 | 68 | }
|
0 commit comments