EoinDavey / tsPEG

PEG Parser Generator for TypeScript
Mozilla Public License 2.0
192 stars 7 forks source link

using a token named 'object' breaks the code #44

Closed feliksik closed 1 year ago

feliksik commented 1 year ago

What a great library! Just discovered it.

Small bug: the javascript is invalid with this grammar

start := object
object := '[A-Za-z]+'

because it generates code like

export type object = string

This is not a valid type alias name in Typescript.

Solution should be trivial, e.g. postfix the illegal name(s) with a string, e.g. "object" -> "objectType". Probably not nice for all names (for usability and breaking existing client code).

Even failing to generate the code if 'object' is used would be a bit nicer than having illegal typescript code, as I didn't immediately realize what the problem was :-)