Skip to content

Commit

Permalink
Revert "Simplify making the last statement an expression a return (#500
Browse files Browse the repository at this point in the history
…)"

This reverts commit aa45410.
  • Loading branch information
bencroker committed Jan 20, 2025
1 parent e99c9e0 commit 91483ab
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions library/src/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>()
Expand Down

0 comments on commit 91483ab

Please sign in to comment.