fix: uniquify results

This commit is contained in:
cha0s 2020-06-25 07:44:01 -05:00
parent 770db27eaa
commit 8c657994b4

View File

@ -59,11 +59,13 @@ export const candidates = (description, type) => {
const inverted = invertedDigraph();
const typeParts = type.split('|');
if (typeParts.length > 1) {
return typeParts.reduce((r, typePart) => r.concat(candidates(description, typePart)), []);
return arrayUnique(
typeParts.reduce((r, typePart) => r.concat(candidates(description, typePart)), [])
);
}
const types = (inverted[type] || []).concat(type);
const {children} = description;
const c = 'any' === type
return arrayUnique('any' === type
? Object.keys(children)
: Object.entries(children)
.reduce((r, [key, {type}]) => (
@ -72,8 +74,8 @@ export const candidates = (description, type) => {
? [key]
: []
)
), []);
return c;
), [])
);
};
export function description(type, instance) {
@ -82,23 +84,37 @@ export function description(type, instance) {
children: {},
type,
};
if (!allTypes[type]) {
return {
...defaults,
type: 'undefined',
};
const splitTypes = type.split('|');
for (let i = 0; i < splitTypes.length; i++) {
const type = splitTypes[i];
if (allTypes[type]) {
return {
...defaults,
...('function' === typeof allTypes[type] ? allTypes[type](instance) : allTypes[type])
};
}
}
return {
...defaults,
...('function' === typeof allTypes[type] ? allTypes[type](instance) : allTypes[type])
type: 'undefined',
};
}
export function fitsInto(candidate, reference) {
if ('any' === reference) {
return true;
const candidates = candidate.split('|');
const references = candidate.split('|');
for (let i = 0; i < references.length; i++) {
if ('any' === references[i]) {
return true;
}
for (let j = 0; j < candidates.length; j++) {
const refer = candidates[j];
if (references[i] === candidates[j]) {
return true;
}
}
}
return -1 !== reference.split('|').map((type) => type.trim()).indexOf(candidate);
return false;
}
export function fromLiteral(value) {