-
-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(js_parser): handle edge cases for arrow expression in tenary #1113
fix(js_parser): handle edge cases for arrow expression in tenary #1113
Conversation
✅ Deploy Preview for biomejs canceled.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! Thanks for your contribution!
I just suggested renaming consequence
and alternative
to consequent
and alternate
. Are there some specific reasons you chose consequence
and alternative
?
Co-authored-by: Victorien Elvinger <[email protected]>
Co-authored-by: Victorien Elvinger <[email protected]>
No just mixing up some words, will regenerate test files and change naming of the other tests as well 👍 |
Summary
When looking at what caused the issues describe in #1077 I first noticed that the consequent block was parsed as a arrow expression because when we try to parse an arrow function we also check for typescript return parameter.
E.g for
a ? (b) : <p>{() => null}</p>;
everything after:
and up until=>
was parsed as the return parameter resulting in this being true.My first try to fix this was to return an error when
ambiguity.is_disallowed()
was true and if the parsed typescript return parameter was bogus.While this worked for this perticular case I started to play around with different tenary expressions that could generate the same result but with valid typescript syntax and found:
This expression failed both when parsing typescript and javascript but with different errors and checking for bogus typescript return type was not fixing this case.
So instead I created a specialized version of
parse_assignment_expression_or_higher
to use when parsing the consequent block of a tenary expression.Playground link:
https://biomejs.dev/playground/?indentStyle=space&code=YQAgAD8AIAAoAGIAKQAgADoAIABhACAAPQA%2BACAAewB9ADsACgBhACAAPwAgACgAYgApACAAOgAgADwAcAA%2BAHsAKAApACAAPQA%2BACAAbgB1AGwAbAB9ADwALwBwAD4AOwA%3D
Closes: #1077
Test Plan
Added new test