negation.js
1 import * as Plan from './plan.js' 2 import * as JSON from '../json.js' 3 import { toDebugString } from '../debug.js' 4 5 export class Negation { 6 /** 7 * @param {Plan.Constraint} operand 8 */ 9 constructor(operand) { 10 this.operand = operand 11 } 12 13 /** 14 * @param {Plan.EvaluationContext} context 15 */ 16 *evaluate({ selection, ...context }) { 17 const matches = [] 18 for (const frame of selection) { 19 const excluded = yield* this.operand.evaluate({ 20 ...context, 21 selection: [frame], 22 }) 23 24 if (excluded.length === 0) { 25 matches.push(frame) 26 } 27 } 28 29 return matches 30 } 31 32 toJSON() { 33 return { not: JSON.from(this.operand) } 34 } 35 36 toDebugString() { 37 return `{ not: ${toDebugString(this.operand)} }` 38 } 39 }