Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
path.get("properties").each(propertyPath => {
let propDescriptor, valuePath, type, resolvedValuePath;
const nodeType = propertyPath.node.type;
if (nodeType === types.Property.name) {
propDescriptor = documentation.getPropDescriptor(
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
path.get('properties').each((propertyPath: any) => {
let propDescriptor, valuePath, type, resolvedValuePath
const nodeType = propertyPath.node.type
if (nodeType === types.Property.name) {
propDescriptor = documentation.getPropDescriptor(
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
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,
};
}
});
}
propsToPatch.each((propertyPath: string) => {
const propDescriptor = doc.getPropDescriptor(
utils.getPropertyName(propertyPath)
)
if (propDescriptor.type.name === 'enum' && propDescriptor.type.computed) {
const oldVal = propDescriptor.type.value
const newVal = getComputedPropVal(propDescriptor.type.value) || oldVal
propDescriptor.type.value = newVal
propDescriptor.type.computed = false
}
})
}