Skip to content
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

Remove unnecessary parentheses between ? and : in ternary expressions #396

Merged
merged 1 commit into from
May 13, 2024

Conversation

therontarigo
Copy link
Contributor

The rules for how ? : parse:

  • everything between ? and : is parsed as if grouped (just like ( ) and { }), so the parens can always be omitted from the middle expression.
  • The entire ? expr : is parsed as if it is one whole binary operator in relation to the expressions on either side of it, according to normal precedence rules, thus ?: gets its spot in the precedence table in the spec despite its more complex grammar.

Copy link
Owner

@laurentlb laurentlb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@laurentlb laurentlb merged commit 5b9066c into laurentlb:master May 13, 2024
1 check passed
@therontarigo therontarigo deleted the ternaryprecedence branch May 15, 2024 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants