Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function findPropTypesDefinitions(ast, recast) {
const definitions = resolver.findAllComponentDefinitions(ast, recast);
function objectVisitor(path) {
// Just check that `propTypes` is present on the object.
const propTypes = utils.getPropertyValuePath(path, 'propTypes');
if (propTypes) {
definitions.push(path);
}
return false;
}
// The default resolver doesn't traverse function bodies, which means that
// HOCs propTypes are ignored.
function classVisitor(path) {
if (utils.isReactComponentClass(path) && definitions.indexOf(path) === -1) {
definitions.push(path);
}
function combinedResolver(ast, recast) {
const exportedComponents = resolver.findAllComponentDefinitions(ast, recast);
const annotated = annotationResolver(ast, recast);
return exportedComponents.concat(annotated);
}
module.exports = (ast, recast) => {
const {
types: { namedTypes: types },
} = recast;
let components = resolver.findAllComponentDefinitions(ast, recast);
const getComment = path => {
let searchPath = path;
while (searchPath && !types.Statement.check(searchPath.node)) {
searchPath = searchPath.parent;
}
let comment =
(searchPath &&
searchPath.node.leadingComments &&
searchPath.node.leadingComments.map(c => c.value).pop()) ||
null;
if (comment) comment = `/${comment}*/`;
return comment;
};