Font editer coming a long. first font is looking good. some parser changes to accomodate any string as record fields. other stuff
This commit is contained in:
parent
e3b8930111
commit
d79166a5bc
6 changed files with 4987 additions and 25 deletions
|
|
@ -56,7 +56,7 @@ export function compile(ast: AST, ctx: CompileCtx = defaultCtx): string {
|
|||
const parts = ast.entries.map(entry =>
|
||||
entry.kind === 'spread'
|
||||
? `...${compile(entry.expr, ctx)}`
|
||||
: `${sanitizeName(entry.key)}: ${compile(entry.value, ctx)}`
|
||||
: `${JSON.stringify(entry.key)}: ${compile(entry.value, ctx)}`
|
||||
)
|
||||
return `({${parts.join(', ')}})`;
|
||||
}
|
||||
|
|
@ -69,11 +69,11 @@ export function compile(ast: AST, ctx: CompileCtx = defaultCtx): string {
|
|||
}
|
||||
|
||||
case 'record-access':
|
||||
return `${compile(ast.record, ctx)}.${sanitizeName(ast.field)}`;
|
||||
return `${compile(ast.record, ctx)}[${JSON.stringify(ast.field)}]`;
|
||||
|
||||
case 'record-update':
|
||||
const updates = Object.entries(ast.updates)
|
||||
.map(([k, v]) => `${sanitizeName(k)}: ${compile(v, ctx)}`);
|
||||
.map(([k, v]) => `${JSON.stringify(k)}: ${compile(v, ctx)}`);
|
||||
return `({...${compile(ast.record, ctx)}, ${updates.join(', ')}})`;
|
||||
|
||||
case 'let': {
|
||||
|
|
@ -207,7 +207,7 @@ function compilePattern(pattern: Pattern, expr: string): { condition: string, bi
|
|||
let condition = 'true';
|
||||
const bindings: string[] = [];
|
||||
for (const [field, fieldPattern] of Object.entries(pattern.fields)) {
|
||||
const sub = compilePattern(fieldPattern, `${expr}.${sanitizeName(field)}`);
|
||||
const sub = compilePattern(fieldPattern, `${expr}[${JSON.stringify(field)}]`);
|
||||
if (sub.condition !== 'true') condition += ` && ${sub.condition}`;
|
||||
bindings.push(...sub.bindings);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue