cucapra/braid

Use TypeScript tagged unions for AST nodes and types

sampsyo opened this issue · 0 comments

I originally wrote the AST and type hierarchy for Braid before TypeScript gained its support for faking tagged unisons with a feature called “type narrowing.” We could get rid of a lot of boilerplate and unnecessary casting by embracing this feature. This will require making a giant union type of all possible AST node types and using this in place of the current SyntaxNode base interface.

With this in place, it may be possible to replace much of the visitor library with plain switch starements. With the right code structure, TypeScript can require these switches to be exhaustive.