Ternary with numbers fails to parse when minified #33

Closed
opened 2024-04-23 09:27:50 +02:00 by szuend · 2 comments
szuend commented 2024-04-23 09:27:50 +02:00 (Migrated from github.com)

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?

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?
marijnh commented 2024-04-23 11:18:32 +02:00 (Migrated from github.com)

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.

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.
szuend commented 2024-04-23 12:19:17 +02:00 (Migrated from github.com)

Nice! Thanks for the fast fix.

Nice! Thanks for the fast fix.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lezer/javascript#33
No description provided.