in src/handlers/defaultPropsHandler.ts [92:136]
function getDefaultValuesFromProps(
properties: NodePath,
documentation: Documentation,
isStateless: boolean,
importer: Importer,
) {
properties
// Don't evaluate property if component is functional and the node is not an AssignmentPattern
.filter(
propertyPath =>
!isStateless ||
t.AssignmentPattern.check(propertyPath.get('value').node),
null,
)
.forEach(propertyPath => {
if (t.Property.check(propertyPath.node)) {
const propName = getPropertyName(propertyPath, importer);
if (!propName) return;
const propDescriptor = documentation.getPropDescriptor(propName);
const defaultValue = getDefaultValue(
isStateless
? propertyPath.get('value', 'right')
: propertyPath.get('value'),
importer,
);
if (defaultValue) {
propDescriptor.defaultValue = defaultValue;
}
} else if (t.SpreadElement.check(propertyPath.node)) {
const resolvedValuePath = resolveToValue(
propertyPath.get('argument'),
importer,
);
if (t.ObjectExpression.check(resolvedValuePath.node)) {
getDefaultValuesFromProps(
resolvedValuePath.get('properties'),
documentation,
isStateless,
importer,
);
}
}
});
}