Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const setPropDescription = require("react-docgen/dist/utils/setPropDescription")
.default;
let babylon;
try {
const buildParser = require("react-docgen/dist/babelParser").default;
babylon = buildParser();
} catch (e) {
// Try babylon if requiring babelParser fails, but don't mask Babel config errors
if (e.message.indexOf("Cannot find module") === -1) {
throw e;
}
// eslint-disable-next-line node/no-missing-require
babylon = require("react-docgen/dist/babylon").default;
}
const utils = require("react-docgen").utils;
const types = recast.types.namedTypes;
const HOP = Object.prototype.hasOwnProperty;
const createObject = Object.create;
function isPropTypesExpression(path) {
const moduleName = utils.resolveToModule(path);
if (moduleName) {
return (
utils.isReactModuleName(moduleName) || moduleName === "ReactPropTypes"
);
}
return false;
}
function deprecatedPropTypeHandler(documentation, path) {
let propTypesPath = docgen.utils.getMemberValuePath(path, 'propTypes');
if (!propTypesPath) {
return;
}
propTypesPath = docgen.utils.resolveToValue(propTypesPath);
if (!propTypesPath || propTypesPath.node.type !== 'ObjectExpression') {
return;
}
// Checks for deprecatedPropType function and add deprecation info.
propTypesPath.get('properties').each(function(propertyPath) {
const valuePath = docgen.utils.resolveToValue(propertyPath.get('value'));
// If it's a call to deprecatedPropType, do stuff
if (valuePath.node.type !== 'CallExpression' ||
valuePath.node.callee.name !== 'deprecatedPropType') {
return;
function deprecatedPropTypeHandler(documentation, path) {
let propTypesPath = docgen.utils.getMemberValuePath(path, 'propTypes');
if (!propTypesPath) {
return;
}
propTypesPath = docgen.utils.resolveToValue(propTypesPath);
if (!propTypesPath || propTypesPath.node.type !== 'ObjectExpression') {
return;
}
// Checks for deprecatedPropType function and add deprecation info.
propTypesPath.get('properties').each(function(propertyPath) {
const valuePath = docgen.utils.resolveToValue(propertyPath.get('value'));
// If it's a call to deprecatedPropType, do stuff
if (valuePath.node.type !== 'CallExpression' ||
valuePath.node.callee.name !== 'deprecatedPropType') {
return;
}
const propDescriptor = documentation.getPropDescriptor(
docgen.utils.getPropertyName(propertyPath)
);
// The 2nd argument of deprecatedPropType is the deprecation message.
visitAssignmentExpression: function(astPath) {
if (!definition && docgen.utils.isExportsOrModuleAssignment(astPath)) {
definition = docgen.utils.resolveToValue(astPath.get('right'));
}
return false;
}
});
visitAssignmentExpression: function(astPath) {
if (!definition && docgen.utils.isExportsOrModuleAssignment(astPath)) {
definition = docgen.utils.resolveToValue(astPath.get('right'));
}
return false;
}
});
doc.methods = (doc.methods || []).filter(method => {
const doclets = method.docblock && reactDocs.utils.docblock.getDoclets(method.docblock);
return doclets && doclets.public;
});
visitAssignmentExpression: function(path) {
if (!objPath && docgen.utils.isExportsOrModuleAssignment(path)) {
objPath = docgen.utils.resolveToValue(path.get('right'))
}
return false
},
})
const getDocletsObject = string => ({ ...reactDocs.utils.docblock.getDoclets(string) });
visitAssignmentExpression: function(astPath) {
if (!definition && docgen.utils.isExportsOrModuleAssignment(astPath)) {
definition = docgen.utils.resolveToValue(astPath.get('right'));
}
return false;
}
});
visitAssignmentExpression: function(path) {
if (!objPath && docgen.utils.isExportsOrModuleAssignment(path)) {
objPath = docgen.utils.resolveToValue(path.get('right'))
}
return false
},
})