nested rebind now works

This commit is contained in:
Dustin Swan 2026-02-09 15:22:07 -07:00
parent 559191c65e
commit f378149146
No known key found for this signature in database
GPG key ID: 30D46587E2100467
4 changed files with 84 additions and 85 deletions

View file

@ -74,15 +74,10 @@ export function compile(ast: AST): string {
if (ast.target.kind === 'variable') {
return `({ _tag: "Rebind", _0: "${ast.target.name}", _1: ${compile(ast.value)} })`;
} else if (ast.target.kind === 'record-access') {
let current: AST = ast.target;
const path: string[] = [];
while (current.kind === 'record-access') {
path.unshift(current.field);
current = current.record;
}
if (current.kind === 'variable') {
return `({ _tag: "Rebind", _0: "${current.name}", _1: ${JSON.stringify(path)}, _2: ${compile(ast.value)} })`;
}
const field = ast.target.field;
const obj = compile(ast.target.record);
const value = compile(ast.value);
return `(() => { ${obj}.${sanitize(field)} = ${value}; return { _tag: "Rerender" }; })()`;
}
throw new Error('Invalid rebind target');
}