forked from syndicate-lang/preserves
Further simplification
This commit is contained in:
parent
46ab6d90ec
commit
0f1ea4aa20
|
@ -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}`))];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue