Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
utils.getPropertyName(propertyPath)
);
valuePath = propertyPath.get("value");
type = isPropTypesExpression(valuePath)
? utils.getPropType(valuePath)
: {
name: "custom",
raw: utils.printValue(valuePath)
};
if (type) {
propDescriptor.type = type;
propDescriptor.required =
type.name !== "custom" && isRequiredPropType(valuePath);
}
} else if (nodeType === types.SpreadProperty.name) {
resolvedValuePath = utils.resolveToValue(propertyPath.get("argument"));
// normal object literal
if (resolvedValuePath.node.type === types.ObjectExpression.name) {
amendPropTypes(documentation, resolvedValuePath);
}
}
if (types.Property.check(propertyPath.node)) {
setPropDescription(documentation, propertyPath);
}
});
}
utils.getPropertyName(propertyPath)
)
valuePath = propertyPath.get('value')
type = isPropTypesExpression(valuePath)
? utils.getPropType(valuePath)
: {
name: 'custom',
raw: utils.printValue(valuePath),
}
if (type) {
propDescriptor.type = type
propDescriptor.required =
type.name !== 'custom' && isRequiredPropType(valuePath)
}
} else if (nodeType === types.SpreadProperty.name) {
resolvedValuePath = utils.resolveToValue(propertyPath.get('argument'))
// normal object literal
if (resolvedValuePath.node.type === types.ObjectExpression.name) {
amendPropTypes(documentation, resolvedValuePath)
}
}
if (types.Property.check(propertyPath.node)) {
setPropDescription(documentation, propertyPath)
}
})
}
return (doc, path) => {
const root = path.scope.getGlobalScope().node;
let propTypesPath, propTypesFilePath, propTypesAST;
propTypesPath = utils.getMemberValuePath(path, "propTypes");
propTypesAST = root;
propTypesFilePath = componentPath;
if (!propTypesPath) {
return;
}
const propsNameIdentifier = propTypesPath.node.name;
propTypesPath = utils.resolveToValue(propTypesPath);
if (!propTypesPath) {
return;
}
if (!types.ObjectExpression.check(propTypesPath.node)) {
//First resolve dependencies against component path
propTypesFilePath = resolveFilePath(
componentPath,
propTypesPath.node.source.value
);
const propTypesSrc = getSrc(propTypesFilePath);
propTypesAST = getAST(propTypesSrc);
const importedPropTypes = getIdentifiers(propTypesAST)[
propsNameIdentifier
];
return (doc: any, path: any) => {
const root = path.scope.getGlobalScope().node
let propTypesPath, propTypesFilePath, propTypesAST
propTypesPath = utils.getMemberValuePath(path, 'propTypes')
propTypesAST = root
propTypesFilePath = componentPath
if (!propTypesPath) {
return
}
const propsNameIdentifier = propTypesPath.node.name
propTypesPath = utils.resolveToValue(propTypesPath)
if (!propTypesPath) {
return
}
if (!types.ObjectExpression.check(propTypesPath.node)) {
//First resolve dependencies against component path
propTypesFilePath = resolveFilePath(
componentPath,
propTypesPath.node.source.value
)
const propTypesSrc = getSrc(propTypesFilePath)
propTypesAST = getAST(propTypesSrc)
const importedPropTypes = getIdentifiers(propTypesAST)[
propsNameIdentifier
]
//First resolve dependencies against component path
propTypesFilePath = resolveFilePath(
componentPath,
propTypesPath.node.source.value
)
const propTypesSrc = getSrc(propTypesFilePath)
propTypesAST = getAST(propTypesSrc)
const importedPropTypes = getIdentifiers(propTypesAST)[
propsNameIdentifier
]
if (!importedPropTypes) {
return
}
propTypesPath = utils.resolveToValue(importedPropTypes.path)
//updating doc object with external props
amendPropTypes(doc, propTypesPath)
}
const computedPropNames = getComputedPropValuesFromDoc(doc)
if (!computedPropNames) {
return
}
const importSpecifiers = getImports(propTypesAST)
if (!importSpecifiers) {
return
}
function propLocHandler(documentation, path) {
let propTypesPath = utils.getMemberValuePath(path, 'propTypes');
if (!propTypesPath) {
return;
}
propTypesPath = utils.resolveToValue(propTypesPath);
if (!propTypesPath || !r.types.namedTypes.ObjectExpression.check(propTypesPath.node)) {
return;
}
propTypesPath.get('properties').each(propertyPath => {
if (r.types.namedTypes.Property.check(propertyPath.node)) {
const propName = utils.getPropertyName(propertyPath);
const propDescriptor = documentation.getPropDescriptor(propName);
propDescriptor.loc = {
start: propertyPath.get('value').value.start,
end: propertyPath.get('value').value.end,
};
}
});
}
//First resolve dependencies against component path
propTypesFilePath = resolveFilePath(
componentPath,
propTypesPath.node.source.value
);
const propTypesSrc = getSrc(propTypesFilePath);
propTypesAST = getAST(propTypesSrc);
const importedPropTypes = getIdentifiers(propTypesAST)[
propsNameIdentifier
];
if (!importedPropTypes) {
return;
}
propTypesPath = utils.resolveToValue(importedPropTypes.path);
//updating doc object with external props
amendPropTypes(doc, propTypesPath);
}
const computedPropNames = getComputedPropValuesFromDoc(doc);
if (!computedPropNames) {
return;
}
const importSpecifiers = getImports(propTypesAST);
if (!importSpecifiers) {
return;
}