namspacing and lowercasing ui functions. they're functions, not data constructors now. matching CG userspace ui functions
This commit is contained in:
parent
b8a396a734
commit
3fe7750290
6 changed files with 126 additions and 99 deletions
|
|
@ -18,7 +18,7 @@ export function compile(ast: AST): string {
|
|||
return sanitize(ast.name);
|
||||
|
||||
case 'lambda':
|
||||
const params = ast.params.map(sanitize).join(') => (');
|
||||
const params = ast.params.map(sanitizeName).join(') => (');
|
||||
return `Object.assign((${params}) => ${compile(ast.body)}, { _ast: (${JSON.stringify(ast)}) })`;
|
||||
|
||||
case 'apply':
|
||||
|
|
@ -36,7 +36,7 @@ export function compile(ast: AST): string {
|
|||
|
||||
case 'record': {
|
||||
const fields = Object.entries(ast.fields)
|
||||
.map(([k, v]) => `${sanitize(k)}: ${compile(v)}`);
|
||||
.map(([k, v]) => `${sanitizeName(k)}: ${compile(v)}`);
|
||||
return `({${fields.join(', ')}})`;
|
||||
}
|
||||
|
||||
|
|
@ -48,15 +48,15 @@ export function compile(ast: AST): string {
|
|||
}
|
||||
|
||||
case 'record-access':
|
||||
return `${compile(ast.record)}.${sanitize(ast.field)}`;
|
||||
return `${compile(ast.record)}.${sanitizeName(ast.field)}`;
|
||||
|
||||
case 'record-update':
|
||||
const updates = Object.entries(ast.updates)
|
||||
.map(([k, v]) => `${sanitize(k)}: ${compile(v)}`);
|
||||
.map(([k, v]) => `${sanitizeName(k)}: ${compile(v)}`);
|
||||
return `({...${compile(ast.record)}, ${updates.join(', ')}})`;
|
||||
|
||||
case 'let':
|
||||
return `((${sanitize(ast.name)}) =>
|
||||
return `((${sanitizeName(ast.name)}) =>
|
||||
${compile(ast.body)})(${compile(ast.value)})`;
|
||||
|
||||
case 'match':
|
||||
|
|
@ -98,9 +98,13 @@ function sanitize(name: string): string {
|
|||
|
||||
if (ops[name]) return ops[name];
|
||||
|
||||
const natives = ['measure', 'measureText', 'storeSearch', 'getSource', 'debug', 'len', 'slice', 'str', 'redefine'];
|
||||
const natives = ['measure', 'measureText', 'storeSearch', 'getSource', 'debug', 'len', 'slice', 'str', 'redefine', 'stateful', 'batch', 'noOp', 'rerender', 'focus', 'ui'];
|
||||
if (natives.includes(name)) return `_rt.${name}`;
|
||||
|
||||
return sanitizeName(name);
|
||||
}
|
||||
|
||||
function sanitizeName(name: string): string {
|
||||
const reserved = [
|
||||
'default','class','function','return','const','let','var',
|
||||
'if','else','switch','case','for','while','do','break',
|
||||
|
|
@ -138,7 +142,7 @@ function compilePattern(pattern: Pattern, expr: string): { condition: string, bi
|
|||
return { condition: 'true', bindings: [] };
|
||||
|
||||
case 'var':
|
||||
return { condition: 'true', bindings: [`${sanitize(pattern.name)} = ${expr}`] };
|
||||
return { condition: 'true', bindings: [`${sanitizeName(pattern.name)} = ${expr}`] };
|
||||
|
||||
case 'literal':
|
||||
return { condition: `${expr} === ${JSON.stringify(pattern.value)}`, bindings: [] };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue