nested rebind now works
This commit is contained in:
parent
559191c65e
commit
f378149146
4 changed files with 84 additions and 85 deletions
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue