lezer-parser/javascript

Ternary with numbers fails to parse when minified

Closed this issue · 2 comments

Not sure how relevant this is for authored code, but bundlers remove spaces and leading zeroes from numbers. The snippet

foo?.1:2

currently fails to parse. Since I'm only superficially familiar with how Lezer grammar works, I don't actually know how a fix would look like. I'd have expected the parser to backtrack from the failed MemberExpression and try the ConditionalExpression, but maybe the tokenizer eagerly combined the ?. so the ConditionalExpression can't be applied?

This seems to be something to handle at the token level—?. is only a deref operator when not followed by a digit. Attached patch uses an external tokenizer to implement it that way.

Nice! Thanks for the fast fix.