Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let description;
if (propType.leadingComments) {
description = propType.leadingComments.reduce((acc, { value }) => acc.concat(`\n${value}`), '');
}
if (!propType.value) {
// eslint-disable-next-line no-console
console.error(
`Prop ${
propType.key
} has no type; this usually indicates invalid propType or defaultProps config`
);
return null;
}
const name = propType.kind === 'spread' ? '...' : convert(propType.key);
const OverrideComponent = overrides[name];
const commonProps = {
components,
name,
key: name,
required: !propType.optional,
type: getKind(propType.value),
defaultValue: propType.default && convert(propType.default),
description,
shouldCollapse: shouldCollapseProps,
typeValue: propType.value
};
return overrides[name] ? : ;
};
string: (type: K.String, components: Components) => {
if (type.value != null) {
return {convert(type)};
}
return {convert(type)};
},
// nullable types are currently stripping infromation, as we show 'required'
string: (type: K.String, components: Components) => {
if (type.value != null) {
return {convert(type)};
}
return {convert(type)};
},
// nullable types are currently stripping infromation, as we show 'required'
string: (type: K.String, components: Components) => {
if (type.value != null) {
return {convert(type)};
}
return {convert(type)};
},
// nullable types are currently stripping infromation, as we show 'required'
render() {
let { shouldCollapse, typeValue: type, components } = this.props;
// any instance of returning null means we are confident the information will
// be displayed elsewhere so we do not need to also include it here.
if (type.kind === 'generic') {
type = resolveFromGeneric(type);
}
if (SIMPLE_TYPES.includes(type.kind)) return null;
if (type.kind === 'nullable' && SIMPLE_TYPES.includes(type.arguments.kind)) {
return null;
}
return shouldCollapse ? (
(
<div>
{isCollapsed ? 'Expand Prop Shape' : 'Hide Prop Shape'}
</div>
)}
{type.members.map(prop => {
if (prop.kind === "spread") {
const nestedObj = resolveFromGeneric(prop.value);
// Spreads almost always resolve to an object, but they can
// also resolve to an import. We just allow it to fall through
// to prettyConvert if there are no members
if (nestedObj.members) {
return nestedObj.members.map(newProp =>
prettyConvert(newProp, components, depth)
);
}
}
return prettyConvert(prop, components, depth);
})}
{type.members.map(prop => {
if (prop.kind === 'spread') {
const nestedObj = resolveFromGeneric(prop.value);
// Spreads almost always resolve to an object, but they can
// also resolve to an import. We just allow it to fall through
// to prettyConvert if there are no members
if (nestedObj.members) {
return nestedObj.members.map(newProp =>
prettyConvert(newProp, components, depth),
);
}
}
return prettyConvert(prop, components, depth);
})}
{type.members.filter(p => p).map(prop => {
if (prop.kind === 'spread') {
const nestedObj = resolveFromGeneric(prop.value);
// Spreads almost always resolve to an object, but they can
// also resolve to an import. We just allow it to fall through
// to prettyConvert if there are no members
if (nestedObj.members) {
return nestedObj.members.map(newProp =>
prettyConvert(newProp, components, depth)
);
}
}
return prettyConvert(prop, components, depth);
})}
render() {
let { shouldCollapse, typeValue: type, components } = this.props;
// any instance of returning null means we are confident the information will
// be displayed elsewhere so we do not need to also include it here.
if (type.kind === "generic") {
type = resolveFromGeneric(type);
}
if (SIMPLE_TYPES.includes(type.kind)) return null;
if (
type.kind === "nullable" &&
SIMPLE_TYPES.includes(type.arguments.kind)
) {
return null;
}
return shouldCollapse ? (
(
<div>
</div>
const renderPropType = (
propType: any,
{ overrides = {}, shouldCollapseProps, components }: any
) => {
if (!components) {
components = allComponents;
} else {
components = { ...allComponents, ...components };
}
if (propType.kind === 'spread') {
const furtherProps = reduceToObj(propType.value);
if (Array.isArray(furtherProps) && furtherProps.length > 0) {
/* Only render the spread contents if they are a non-empty value, otherwise render the
* spread itself so we can see the spread of generics and other types that have not been
* converted into an object */
return furtherProps.map(p =>
renderPropType(p, { overrides, shouldCollapseProps, components })
);
}
}
let description;
if (propType.leadingComments) {
description = propType.leadingComments.reduce((acc, { value }) => acc.concat(`\n${value}`), '');
}
if (!propType.value) {