diff --git a/actor.ts b/actor.ts index 80faa28..5786122 100644 --- a/actor.ts +++ b/actor.ts @@ -131,9 +131,7 @@ export class Turn { assert(ref: Ref, assertion: Assertion): Handle { const h = nextHandle++; this.enqueue(ref.relay, t => { - const a = ref.attenuation === void 0 - ? assertion - : runRewrites(ref.attenuation, assertion); + const a = runRewrites(ref.attenuation, assertion); if (a !== null) { this.actor.outbound.set(h, ref); ref.target.assert?.(t, a, h); @@ -167,9 +165,7 @@ export class Turn { } message(ref: Ref, assertion: Assertion): void { - const a = ref.attenuation === void 0 - ? assertion - : runRewrites(ref.attenuation, assertion); + const a = runRewrites(ref.attenuation, assertion); if (a !== null) this.enqueue(ref.relay, t => ref.target.message?.(t, assertion)); } @@ -261,11 +257,13 @@ export function rewrite(r: Rewrite, v: Assertion): Assertion | null { return instantiate(r.template, bindings); } -export function runRewrites(a: Attenuation, v: Assertion): Assertion | null { - for (const r of a) { - const w = rewrite(r, v); - if (w === null) return null; - v = w; +export function runRewrites(a: Attenuation | undefined, v: Assertion): Assertion | null { + if (a !== void 0) { + for (const r of a) { + const w = rewrite(r, v); + if (w === null) return null; + v = w; + } } return v; }