Further simplification

This commit is contained in:
Tony Garnock-Jones 2021-05-21 16:01:04 +02:00
parent 46ab6d90ec
commit 0f1ea4aa20
1 changed files with 10 additions and 13 deletions

View File

@ -17,19 +17,16 @@ export function unconverterForDefinition(
return [seq(`return `, unconverterFor(
ctx, p.pattern, hasValueField ? `${src}.value` : src))];
})))))];
case 'and': {
const ps = [def.pattern0, def.pattern1, ... def.patternN];
const cs = ps.flatMap(p => {
if (p._variant === 'anonymous' && p.value._variant === 'SimplePattern') {
return [];
} else {
return [unconverterForNamed(ctx, p, src)];
}
});
return [seq(`return `, (cs.length === 1)
? cs[0]
: seq(`_.merge`, parens(`(a, b) => (a === b) ? a : void 0`, ... cs)))];
}
case 'and':
return [seq(`return _.merge`, parens(
`(a, b) => (a === b) ? a : void 0`,
... [def.pattern0, def.pattern1, ... def.patternN].flatMap(p => {
if (p._variant === 'anonymous' && p.value._variant === 'SimplePattern') {
return [];
} else {
return [unconverterForNamed(ctx, p, src)];
}
})))];
case 'Pattern':
return [seq(`return `, unconverterFor(ctx, def.value, `${src}`))];
}