[FIX] compiler: handle t-set as functions

This commit is contained in:
Géry Debongnie
2021-12-22 15:06:28 +01:00
committed by Aaron Bohy
parent 75ad0835e9
commit 5bf47500d5
9 changed files with 416 additions and 40 deletions
+9 -2
View File
@@ -966,10 +966,17 @@ export class CodeGenerator {
this.helpers.add("isBoundary").add("withDefault");
const expr = ast.value ? compileExpr(ast.value || "") : "null";
if (ast.body) {
const initialTarget = this.target;
this.helpers.add("LazyValue");
let name = this.generateId("value");
const fn = new CodeTarget(name);
this.targets.push(fn);
this.target = fn;
const subCtx: Context = createContext(ctx);
const nextId = `b${BlockDescription.nextBlockId}`;
this.compileAST({ type: ASTType.Multi, content: ast.body }, subCtx);
const value = ast.value ? (nextId ? `withDefault(${expr}, ${nextId})` : expr) : nextId;
this.target = initialTarget;
let value = `new LazyValue(${name}, ctx, node)`;
value = ast.value ? (value ? `withDefault(${expr}, ${value})` : expr) : value;
this.addLine(`ctx[\`${ast.name}\`] = ${value};`);
} else {
let value: string;