peggyjs / peggy

Peggy: Parser generator for JavaScript
https://peggyjs.org/
MIT License
906 stars 64 forks source link

Better type checking for visitor #437

Closed markw65 closed 8 months ago

markw65 commented 11 months ago

I noticed some of the checking was just string rather than the actual node types.

This ensures that every node type is actually implemented in the visitor by checking that the set of "visited" types matches the set of declared types.

It looks like we could also just look at ReturnType<typeof visit> which will be any if we missed any node types in the visitor, and void otherwise. But it would be hard (I think) to generate a meaningful error beyond "not all the node types were handled".

hildjj commented 8 months ago

this one next, please.