From 7cedd6b82e3772b1f4e6be2df3fdd129e62ce717 Mon Sep 17 00:00:00 2001 From: Orion Reed Date: Mon, 2 Dec 2024 16:40:15 -0500 Subject: [PATCH] allow unnamed functions, and throw on nonexistent function calls --- src/folk-event-propagator.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/folk-event-propagator.ts b/src/folk-event-propagator.ts index 49641cf..6bac363 100644 --- a/src/folk-event-propagator.ts +++ b/src/folk-event-propagator.ts @@ -74,8 +74,11 @@ export class FolkEventPropagator extends FolkRope { const key = line_trimmed.slice(0, colonIndex).trim(); const value = line_trimmed.slice(colonIndex + 1).trim(); - if (key.endsWith('()')) { - // If the key is a function call, execute it if the condition is true + if (key === '()') { + // Anonymous function: directly evaluate the value + codeLines.push(`${value};`); + } else if (key.endsWith('()')) { + // If the key is a method, execute it if the condition is true const methodName = key.slice(0, -2); codeLines.push(`if (${value}) { to.${methodName}(); }`); } else { @@ -188,11 +191,13 @@ export class FolkEventPropagator extends FolkRope { }, get(target, prop, receiver) { const value = Reflect.get(target, prop, receiver); + if (value === undefined) { + throw new Error(`Property '${String(prop)}' does not exist on target element.`); + } if (typeof value === 'function') { return value.bind(target); - } else { - return value; } + return value; }, });