forked from syndicate-lang/preserves
Inline single-use function
This commit is contained in:
parent
942fb79a2e
commit
4ee9f99529
|
@ -97,16 +97,6 @@ export function compile(env: Environment, schema: Schema, options: CompilerOptio
|
|||
}
|
||||
}
|
||||
|
||||
function applyPredicate(name: Ref, v: string): Item {
|
||||
return lookup(refPosition(name), name, env,
|
||||
(_p) => `is${Ref._.name(name).description!}(${v})`,
|
||||
(p) => predicateFor(v, p),
|
||||
(mod, modPath, _p) => {
|
||||
imports.add([mod, modPath]);
|
||||
return `${mod}.is${Ref._.name(name).description!}(${v})`;
|
||||
});
|
||||
}
|
||||
|
||||
function predicateFor(v: string, p: Pattern, recordOkAsTuple = false): Item {
|
||||
switch (p.label) {
|
||||
case M.$atom:
|
||||
|
@ -122,7 +112,13 @@ export function compile(env: Environment, schema: Schema, options: CompilerOptio
|
|||
case M.$lit:
|
||||
return `_.is(${v}, ${literal(p[0])})`;
|
||||
case M.$ref:
|
||||
return applyPredicate(p, v);
|
||||
return lookup(refPosition(p), p, env,
|
||||
(_p) => `is${Ref._.name(p).description!}(${v})`,
|
||||
(pp) => predicateFor(v, pp),
|
||||
(mod, modPath, _p) => {
|
||||
imports.add([mod, modPath]);
|
||||
return `${mod}.is${Ref._.name(p).description!}(${v})`;
|
||||
});
|
||||
case M.$or:
|
||||
return opseq('false', ' || ', ... p[0].map(pp => predicateFor(v, pp)));
|
||||
case M.$and:
|
||||
|
|
Loading…
Reference in New Issue