Letting me save things to _ or _myVar to throw it away. fixing printing newlines in strings

This commit is contained in:
Dustin Swan 2026-04-06 17:29:40 -06:00
parent d36f694d80
commit 586d55df85
No known key found for this signature in database
GPG key ID: 30D46587E2100467
3 changed files with 24 additions and 5 deletions

View file

@ -243,7 +243,7 @@ export function prettyPrint(ast: AST, indent = 0): string {
const escaped = val.value
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/\n/g, '\\n')
// .replace(/\n/g, '\\n')
.replace(/\t/g, '\\t');
return `"${escaped}"`;
}
@ -347,13 +347,14 @@ export function prettyPrint(ast: AST, indent = 0): string {
return `...${prettyPrint(ast.spread, indent)}`;
case 'definition':
const displayName = /^_\d+$/.test(ast.name) ? '_' : ast.name;
const ann = ast.annotation
? ` : ${ast.annotation.constraints.length > 0
? ast.annotation.constraints.map(c => `${c.className} ${c.typeVar}`).join(', ') + ' :: '
: ''}${prettyPrintType(ast.annotation.type)}`
: '';
if (!ast.body) return `${ast.name}${ann};`;
return `${ast.name}${ann} = ${prettyPrint(ast.body, indent)};`;
if (!ast.body) return `${displayName}${ann};`;
return `${displayName}${ann} = ${prettyPrint(ast.body, indent)};`;
default:
return `Unknown AST kind: ${i}${(ast as any).kind}`