-
Notifications
You must be signed in to change notification settings - Fork 6
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
Move 'throw' to ParenthesizedExpression #22
base: main
Are you sure you want to change the base?
Conversation
A preview of this PR can be found at https://tc39.es/proposal-throw-expressions/pr/22. |
@bakkot, @michaelficarra, @nicolo-ribaudo: could you take a look? |
Between this and #21, I prefer this solution, though I would also be okay with a solution like this: + ThrowExpression :
+ `throw` ThrowExpression
+ Expression
ParenthesizedExpression :
- `(` Expression `)`
+ `(` ThrowExpression `)` and then in other places where we may want to allow it unparenthesised (though still mostly nonsensical), we could do so: IfStatement :
- `if` `(` Expression `)` Statement `else` Statement
- `if` `(` Expression `)` Statement [lookahead ≠ `else`]
+ `if` `(` ThrowExpression `)` Statement `else` Statement
+ `if` `(` ThrowExpression `)` Statement [lookahead ≠ `else`] These aren't functionally different (other than allowing |
I generally dislike the idea of burying |
I mean you could call it |
IMO, the few marginally useful cases like |
To be clear, the difference I'm talking about here is entirely editorial. There's just the one functional difference (permitting The reason I prefer the structuring that I suggested is because it gives us the freedom to - instance by instance - permit unparenthesised throw expressions in any position we like. This can be done either with the initial proposal or some time later as a loosening. And even if we don't ever want to do that, I don't see it as any less clean. I don't see any downside to doing it like this. |
Actually, another benefit that I hadn't considered until now is that the new top-level production sets up a nice extension point for adding expression forms of other statements in the future, if we decide to do so, which also would very likely be more motivated to be allowed unparenthesised. Yeah I definitely prefer that approach now. |
To be clear, are you stating that you prefer the approach in #21? |
No, and I'm not sure how you would come to that conclusion. |
The wording was unclear. To me, Expression seems more top-level than ParenthesizedExpression, and "that approach" indicated that you preferred an approach that differed from the one in this PR. Hencene request for clarification. |
4da7901
to
beb2541
Compare
beb2541
to
d5a3225
Compare
IMO, Using ThrowExpression to cover both I'm not sure we'd ever want to make more statements directly into expressions. |
I do, and "that approach" was meant to refer to the alternative I had been pondering aloud in the previous comment.
See #22 (comment). I am fine with naming the top-level expression production
I'm not either but it'd be nice if the grammar could accommodate such things without a restructuring, especially if there's no other downside. |
There is already an |
I gave the new production the name NestedExpression. Let me know if that works for now. |
I'm not sure why that concerns you. Ecmarkup has
Sure, that's fine. |
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.
Spec text looks good, and I also prefer this to #21 since the rules for when parentheses are required are simpler (i.e. "always").
I would slightly prefer to use NestedExpression inside if
/while
/do while
to not require double ((
, but it's just out of a purity though and not something that matters in practice (I would be absolutely ok with the current text as-is).
This is one of two alternative approaches to define
throw
expressions such that their operand has the same precedence as the operand to a ThrowStatement. For the alternative approach, see #21In this variant, ThrowExpression is a direct descendant of ParenthesizedExpression, but is mutually exclusive with the
,
operator. This means that ThrowExpression will always require parentheses, even in places where parentheses could potentially be elided:Fixes #23