-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
why are parens required? #55
Comments
This decision was also to give an early hint that it's not the start of a try/catch block. try { // is this a try/catch block or a try-expression of a literal object? const [ok, err, val] = try ({ field: 'value' })
try {
something()
} catch {} It also follows this idea: try {
{ field: 'value' } // label inside an empty code block
} catch {}
try {
({ field: 'value' }) // object literal
} catch {} Try with blocks doesn't make sense in this case because blocks do not evaluate a result. The following code, If you do not generate a value, scoping problems and/or error handling are not an issue following this principle. What should be the result value in the below code? const result = try {
statementOne();
statementTwo();
} That seems to be something that https://github.com/tc39/proposal-do-expressions aims to solve and not this proposal. |
I agree try with blocks doesn't make sense. I think it's reasonable if there's a grammar ambiguity to require the parens here, but then that's the reason, not "consistency with arrows". |
Arrow function bodies also follow this pattern. |
@Arlen22 yes, that mention in the readme prompted the issue in the first place. |
in the "Parentheses Required for Object Literals in try Expressions" section, it says it's mirroring arrow functions - but the only reason arrows have that restriction is because without parens, it'll be a block. Can you do:
? if not, then having this restriction is unnecessary and confusing.
The text was updated successfully, but these errors were encountered: