We're checking types!!!!

This commit is contained in:
Dustin Swan 2026-03-26 18:32:40 -06:00
parent f3c3a76671
commit f272ffaca2
No known key found for this signature in database
GPG key ID: 30D46587E2100467
6 changed files with 304 additions and 24 deletions

View file

@ -142,7 +142,7 @@ export type RecordUpdate = {
export type Definition = {
kind: 'definition'
name: string
body: AST
body?: AST
line?: number
column?: number
start?: number
@ -327,6 +327,7 @@ export function prettyPrint(ast: AST, indent = 0): string {
const ann = ast.annotation
? ` : ${prettyPrintType(ast.annotation.type)}`
: '';
if (!ast.body) return `${ast.name}${ann};`;
return `${ast.name}${ann} = ${prettyPrint(ast.body, indent)};`;
default:
@ -398,18 +399,18 @@ export function prettyPrintType(type: TypeAST): string {
}
}
function prettyPrintTypeDefinition(td: TypeDefinition): string {
const params = td.params.length > 0 ? ' ' + td.params.join(' ') : '';
const ctors = td.constructors.map(c => {
const args = c.args.map(a =>
a.kind === 'type-function' || a.kind === 'type-apply'
? `(${prettyPrintType(a)})`
: prettyPrintType(a)
).join(' ');
return args ? `${c.name} ${args}` : c.name;
}).join(' | ');
return `${td.name}${params} = ${ctors};`;
}
// function prettyPrintTypeDefinition(td: TypeDefinition): string {
// const params = td.params.length > 0 ? ' ' + td.params.join(' ') : '';
// const ctors = td.constructors.map(c => {
// const args = c.args.map(a =>
// a.kind === 'type-function' || a.kind === 'type-apply'
// ? `(${prettyPrintType(a)})`
// : prettyPrintType(a)
// ).join(' ');
// return args ? `${c.name} ${args}` : c.name;
// }).join(' | ');
// return `${td.name}${params} = ${ctors};`;
// }
function needsQuotes(key: string): boolean {
return key === '_' || !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(key);