import {Rule} from "./Rule"; export class SetNextRule extends Rule { /** * The method name to call on the parent object. */ private _methodName:string; /** * Construct a "set next" rule with the specified method name. * * @param methodName Method name of the parent method to call */ constructor(methodName:string) { super(); this._methodName = methodName; } end(name:string):void { const child = this.digester.peek(0); const parent = this.digester.peek(1); const invoker = parent.constructor.prototype[this._methodName]; if (typeof(invoker) !== 'function') { throw new Error(`${parent.constructor.name} no method named "${this._methodName}"`); } invoker.call(parent, child); } }