Files
Shifted/node_modules/react-docgen/dist/utils/getPropertyValuePath.js
2026-02-10 01:14:19 +00:00

19 lines
642 B
JavaScript

import getPropertyName from './getPropertyName.js';
/**
* Given an ObjectExpression, this function returns the path of the value of
* the property with name `propertyName`. if the property is an ObjectMethod we
* return the ObjectMethod itself.
*/
export default function getPropertyValuePath(path, propertyName) {
const property = path
.get('properties')
.find((propertyPath) => !propertyPath.isSpreadElement() &&
getPropertyName(propertyPath) === propertyName);
if (property) {
return property.isObjectMethod()
? property
: property.get('value');
}
return null;
}