propDocblockHandler.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import getMemberValuePath from '../utils/getMemberValuePath.js';
  2. import resolveToValue from '../utils/resolveToValue.js';
  3. import setPropDescription from '../utils/setPropDescription.js';
  4. function resolveDocumentation(documentation, path) {
  5. if (!path.isObjectExpression()) {
  6. return;
  7. }
  8. path.get('properties').forEach((propertyPath) => {
  9. if (propertyPath.isSpreadElement()) {
  10. const resolvedValuePath = resolveToValue(propertyPath.get('argument'));
  11. resolveDocumentation(documentation, resolvedValuePath);
  12. }
  13. else if (propertyPath.isObjectProperty() ||
  14. propertyPath.isObjectMethod()) {
  15. setPropDescription(documentation, propertyPath);
  16. }
  17. });
  18. }
  19. const propDocblockHandler = function (documentation, componentDefinition) {
  20. let propTypesPath = getMemberValuePath(componentDefinition, 'propTypes');
  21. if (!propTypesPath) {
  22. return;
  23. }
  24. propTypesPath = resolveToValue(propTypesPath);
  25. if (!propTypesPath) {
  26. return;
  27. }
  28. resolveDocumentation(documentation, propTypesPath);
  29. };
  30. export default propDocblockHandler;