diff --git a/src/compiler/inline_expressions.ts b/src/compiler/inline_expressions.ts index af67df1c..5840d980 100644 --- a/src/compiler/inline_expressions.ts +++ b/src/compiler/inline_expressions.ts @@ -329,7 +329,7 @@ export function compileExprToArray(expr: string): Token[] { // Mark all variables that have been used locally. // This assumes the expression has only one scope (incorrect but "good enough for now") for (const token of tokens) { - if (token.type === "SYMBOL" && localVars.has(token.value)) { + if (token.type === "SYMBOL" && token.varName && localVars.has(token.value)) { token.originalValue = token.value; token.value = `_${token.value}`; token.isLocal = true; diff --git a/tests/compiler/inline_expressions.test.ts b/tests/compiler/inline_expressions.test.ts index 031f7e25..4743854a 100644 --- a/tests/compiler/inline_expressions.test.ts +++ b/tests/compiler/inline_expressions.test.ts @@ -171,6 +171,9 @@ describe("expression evaluation", () => { ); expect(compileExpr("(ev => ev)(e)")).toBe("(_ev=>_ev)(ctx['e'])"); expect(compileExpr("(v1) => myFunc(v1)")).toBe("(_v1)=>ctx['myFunc'](_v1)"); + expect(compileExpr("list.data.map((data) => data)")).toBe( + "ctx['list'].data.map((_data)=>_data)" + ); }); test.skip("arrow functions: not yet supported", () => { // e is added to localvars in inline_expression but not removed after the arrow func body