fix: handle multipart candidates

This commit is contained in:
cha0s 2020-06-23 22:36:25 -05:00
parent 3628abde5c
commit 0ecbf8a75b

View File

@ -57,9 +57,13 @@ export const invertedDigraph = memoize(() => {
export const candidates = (description, type) => { export const candidates = (description, type) => {
const inverted = invertedDigraph(); const inverted = invertedDigraph();
const typeParts = type.split('|');
if (typeParts.length > 1) {
return typeParts.reduce((r, typePart) => r.concat(candidates(description, typePart)), []);
}
const types = (inverted[type] || []).concat(type); const types = (inverted[type] || []).concat(type);
const {children} = description; const {children} = description;
return 'any' === type const c = 'any' === type
? Object.keys(children) ? Object.keys(children)
: Object.entries(children) : Object.entries(children)
.reduce((r, [key, {type}]) => ( .reduce((r, [key, {type}]) => (
@ -69,6 +73,7 @@ export const candidates = (description, type) => {
: [] : []
) )
), []); ), []);
return c;
}; };
export function description(type, instance) { export function description(type, instance) {