From 91483ab6ff7087c11f71d772c22c76f7ce580f8d Mon Sep 17 00:00:00 2001 From: Ben Croker Date: Mon, 20 Jan 2025 17:10:14 -0600 Subject: [PATCH] Revert "Simplify making the last statement an expression a return (#500)" This reverts commit aa45410ed1c501fd64827cb8525389b9ab680be7. --- library/src/engine/engine.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/src/engine/engine.ts b/library/src/engine/engine.ts index 6d9d355ed..e116d3d11 100644 --- a/library/src/engine/engine.ts +++ b/library/src/engine/engine.ts @@ -203,9 +203,16 @@ export class Engine { ctx: RuntimeContext, ...argNames: string[] ): RuntimeExpressionFunction { - - // Make last statement in an expression a return - let userExpression = ctx.value.replace(/([^;\n]*$)/, 'return ($1);') + const stmts = ctx.value + .split(/;|\n/) + .map((s) => s.trim()) + .filter((s) => s !== '') + const lastIdx = stmts.length - 1 + const last = stmts[lastIdx] + if (!last.startsWith('return')) { + stmts[lastIdx] = `return (${stmts[lastIdx]});` + } + let userExpression = stmts.join(';\n').trim() // Ingore any escaped values const escaped = new Map()