Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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>
return (
<span>
{convert(type.value)}
{type.typeParams &&
type.typeParams.params.map((param, index, array) => (
<span>
{prettyConvert(param, components, depth)}
{type.typeParams && index === array.length - 1 ? '' : ', '}
</span>
))}
</span>
);
}
return prettyConvert(resolveFromGeneric(type), components);
},
object: (type: K.Obj, components: Components, depth: number) => {
return (
<span>
{convert(type.value)}
{type.typeParams &&
type.typeParams.params.map((param, index, array) => (
<span>
{prettyConvert(param, components, depth)}
{type.typeParams && index === array.length - 1 ? "" : ", "}
</span>
))}
</span>
);
}
return prettyConvert(resolveFromGeneric(type), components);
},
object: (type: K.Obj, components: Components, depth: number) => {
const getPropTypes = (propTypesObj: Kind) => {
let resolvedTypes = resolveFromGeneric(propTypesObj);
let propTypes;
if (resolvedTypes.kind === 'object') {
propTypes = resolvedTypes.members;
} else if (resolvedTypes.kind === 'intersection') {
propTypes = resolvedTypes.types.reduce(
(acc, type) => [...acc, ...reduceToObj(type)],
[],
);
}
return propTypes;
};
return (
<span>
{convert(type.value)}
{type.typeParams &&
type.typeParams.params.map((param, index, array) => (
<span>
{prettyConvert(param, components, depth)}
{type.typeParams && index === array.length - 1 ? '' : ', '}
</span>
))}
</span>
);
}
return prettyConvert(resolveFromGeneric(type), components);
},
object: (type: K.Obj, components: Components, depth: number) => {
const getPropTypes = (propTypesObj: Kind) => {
let resolvedTypes = resolveFromGeneric(propTypesObj);
let propTypes;
if (resolvedTypes.kind === 'object') {
propTypes = resolvedTypes.members;
} else if (resolvedTypes.kind === 'intersection') {
propTypes = resolvedTypes.types.reduce((acc, type) => [...acc, ...reduceToObj(type)], []);
}
return propTypes;
};