Further simplification
This commit is contained in:
parent
46ab6d90ec
commit
0f1ea4aa20
|
@ -17,19 +17,16 @@ export function unconverterForDefinition(
|
||||||
return [seq(`return `, unconverterFor(
|
return [seq(`return `, unconverterFor(
|
||||||
ctx, p.pattern, hasValueField ? `${src}.value` : src))];
|
ctx, p.pattern, hasValueField ? `${src}.value` : src))];
|
||||||
})))))];
|
})))))];
|
||||||
case 'and': {
|
case 'and':
|
||||||
const ps = [def.pattern0, def.pattern1, ... def.patternN];
|
return [seq(`return _.merge`, parens(
|
||||||
const cs = ps.flatMap(p => {
|
`(a, b) => (a === b) ? a : void 0`,
|
||||||
|
... [def.pattern0, def.pattern1, ... def.patternN].flatMap(p => {
|
||||||
if (p._variant === 'anonymous' && p.value._variant === 'SimplePattern') {
|
if (p._variant === 'anonymous' && p.value._variant === 'SimplePattern') {
|
||||||
return [];
|
return [];
|
||||||
} else {
|
} else {
|
||||||
return [unconverterForNamed(ctx, p, src)];
|
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 'Pattern':
|
case 'Pattern':
|
||||||
return [seq(`return `, unconverterFor(ctx, def.value, `${src}`))];
|
return [seq(`return `, unconverterFor(ctx, def.value, `${src}`))];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue