|
|
|
@ -220,7 +220,7 @@ export function prettyPrint(ast: AST, indent = 0): string {
|
|
|
|
const parts = ast.entries.map(entry =>
|
|
|
|
const parts = ast.entries.map(entry =>
|
|
|
|
entry.kind === 'spread'
|
|
|
|
entry.kind === 'spread'
|
|
|
|
? `...${prettyPrint(entry.expr, indent + 1)}`
|
|
|
|
? `...${prettyPrint(entry.expr, indent + 1)}`
|
|
|
|
: `${entry.key} = ${prettyPrint(entry.value, indent + 1)}`
|
|
|
|
: `${needsQuotes(entry.key) ? `"${entry.key}"` : entry.key} = ${prettyPrint(entry.value, indent + 1)}`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (parts.length <= 1) return `{ ${parts.join(', ')} }`;
|
|
|
|
if (parts.length <= 1) return `{ ${parts.join(', ')} }`;
|
|
|
|
const inner = parts.map(p => `${' '.repeat(indent + 1)}${p}`).join(',\n');
|
|
|
|
const inner = parts.map(p => `${' '.repeat(indent + 1)}${p}`).join(',\n');
|
|
|
|
@ -238,11 +238,12 @@ export function prettyPrint(ast: AST, indent = 0): string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case 'record-access':
|
|
|
|
case 'record-access':
|
|
|
|
return `${prettyPrint(ast.record, indent)}.${ast.field}`;
|
|
|
|
const field = needsQuotes(ast.field) ? `"${ast.field}"` : ast.field;
|
|
|
|
|
|
|
|
return `${prettyPrint(ast.record, indent)}.${field}`;
|
|
|
|
|
|
|
|
|
|
|
|
case 'record-update': {
|
|
|
|
case 'record-update': {
|
|
|
|
const updates = Object.entries(ast.updates)
|
|
|
|
const updates = Object.entries(ast.updates)
|
|
|
|
.map(([k, v]) => `${k} = ${prettyPrint(v, indent)}`)
|
|
|
|
.map(([k, v]) => `${needsQuotes(k) ? `"${k}"` : k} = ${prettyPrint(v, indent)}`)
|
|
|
|
.join(', ');
|
|
|
|
.join(', ');
|
|
|
|
return `${prettyPrint(ast.record, indent)}.{ ${updates} }`
|
|
|
|
return `${prettyPrint(ast.record, indent)}.{ ${updates} }`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -298,7 +299,7 @@ function prettyPrintPattern(pattern: Pattern): string {
|
|
|
|
|
|
|
|
|
|
|
|
case 'record':
|
|
|
|
case 'record':
|
|
|
|
const fields = Object.entries(pattern.fields)
|
|
|
|
const fields = Object.entries(pattern.fields)
|
|
|
|
.map(([k, p]) => `${k} = ${prettyPrintPattern(p)}`)
|
|
|
|
.map(([k, p]) => `${needsQuotes(k) ? `"${k}"` : k} = ${prettyPrintPattern(p)}`)
|
|
|
|
.join(', ');
|
|
|
|
.join(', ');
|
|
|
|
|
|
|
|
|
|
|
|
return `{${fields}}`;
|
|
|
|
return `{${fields}}`;
|
|
|
|
@ -306,3 +307,7 @@ function prettyPrintPattern(pattern: Pattern): string {
|
|
|
|
return `Unknown AST kind: ${(pattern as any).kind}`
|
|
|
|
return `Unknown AST kind: ${(pattern as any).kind}`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function needsQuotes(key: string): boolean {
|
|
|
|
|
|
|
|
return !/^[a-z_][a-zA-Z0-9_]*$/.test(key);
|
|
|
|
|
|
|
|
}
|
|
|
|
|