-
Notifications
You must be signed in to change notification settings - Fork 23
Disallow mixing nullish coalescing with logical OR via early errors #38
Disallow mixing nullish coalescing with logical OR via early errors #38
Conversation
Are there issues this closes or relates to? |
Why not give them the same precedence, assuming #15 (comment) isn't wrong? |
Same precedence is the status quo, but it's problematic for the reasons laid out in #26 (comment). Of the solutions discussed there, my personal vote would be to lower |
The solution proposed in this PR is wrong, because it is treating the symptom (mixing One of the problems provoked by the wrong precedence and not solved by this PR is apparent when comparing |
Co-Authored-By: Ross Kirsling <[email protected]>
From the last TC39 meeting, we had some general agreement that disallowing the mix of both would be acceptable and would permit us to revisit at a later time. So the rationale to disallow the mix of both is:
My preference would probably be to align with other lower-precedence languages because same precedence feels like it would rarely be what I would want. I also get the sense that it's the behavior I've heard most others (both inside and outside of the committee) favor. If there are no hard objections to lower precedence, I'm willing to bring that up at the next meeting and survey the room. However, I think that forbidding mixing the two is probably the best way to move forward and make progress. |
Any objections to the contents of the spec text? @codehag and @rkirsling? |
I think we should ban mixing Kevin Gibbons created a Grammar Flag parsing at the last meeting that would work perfectly: https://gist.github.com/bakkot/332ddeb26978c41613abc092120448b9 |
@jridgewell would that mean that parens are always syntactically required to mix ?? with ||/&&? |
Yes |
I can add the nullish grammar flag, but I wonder if it's not just cleaner to issue the early error. |
#39 changes the grammar directly, but I'm not sure 4 grammar parameters is the prettiest thing I've seen in this spec. |
I believe the spec text here says what it intends to; it's merely a question of what we want the state of the proposal to be during the upcoming meeting:
Overall though, it would be nice to allow @DanielRosenwasser to try for stage 3 with the status quo reflecting some solution to #26. 😂 |
I don't understand the problem this is pointing at; can you expand? The thing that I get when comparing those under this PR is "the first one behaves reasonably" and "the second one is not valid JS", which, while it is perhaps slightly surprising while performing that transformation, doesn't seem terrible. |
@bakkot Consider some expression mixing operators of different categories: A && B == C You have to learn whether it means A || B == C It would be surprising if the latter triggers a syntax error. But it does work as expected, because every comparison operators ( Returning to the original issue. The root of the problem is that the following is currently not true: “Logical operators ( |
@claudepache Thanks for expanding, that makes sense to me. Your last statement applies equally to #39, strictly speaking (which bans mixing with both |
@DanielRosenwasser FWIW I find the grammar flags much cleaner than prose Early Errors, but that's an editorial question which can be resolved at a later stage. |
My last statement is incomplete, because it overlooked the possibility of completely disallowing the mixing of operators of two distinct categories (in which case, speaking of their relative precedence level is meaningless). — So, no, #39 has not the same issue. |
?? is in the same category as || imo. |
@codehag @rkirsling @jridgewell