-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
rawDefaultPropResolvers.ts
31 lines (25 loc) · 1.2 KB
/
rawDefaultPropResolvers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { TypeResolver, extractFunctionName, createTypeResolvers } from '../lib/defaultValues';
import { createSummaryValue } from '../../../lib';
import { FUNCTION_CAPTION, ELEMENT_CAPTION } from '../lib';
import {
getPrettyElementIdentifier,
getPrettyFuncIdentifier,
} from '../lib/defaultValues/prettyIdentifier';
import { inspectValue, InspectionFunction } from '../lib/inspection';
const funcResolver: TypeResolver = (rawDefaultProp, { name, type }) => {
const isElement = type.summary === 'element' || type.summary === 'elementType';
const funcName = extractFunctionName(rawDefaultProp, name);
if (funcName != null) {
// Try to display the name of the component. The body of the component is omitted since the code has been transpiled.
if (isElement) {
return createSummaryValue(getPrettyElementIdentifier(funcName));
}
const { hasParams } = inspectValue(rawDefaultProp.toString())
.inferredType as InspectionFunction;
return createSummaryValue(getPrettyFuncIdentifier(funcName, hasParams));
}
return createSummaryValue(isElement ? ELEMENT_CAPTION : FUNCTION_CAPTION);
};
export const rawDefaultPropTypeResolvers = createTypeResolvers({
function: funcResolver,
});