(x) => {foo: bar}

Dean Landolt dean at deanlandolt.com
Tue Jan 6 15:18:35 PST 2015

On Tue, Jan 6, 2015 at 3:57 PM, Marius Gundersen <gundersen at gmail.com>

> I don't see how wellLabeledStatement will protect against object literals
> with shorthand properties, like (x, y, z) => {x, y, z}.

It would "protect" against them by disallowing them without the paren
wrapping. A fail-fast SyntaxError beats the hell out of trying to diagnose
an almost imperceptible runtime bug.

>  The solution to the block vs object problem today is to wrap the object
> in parenthesis, but not the block. The only alternative that is easy for
> humans to understand and not ambiguous for machines is to wrap or prefix
> the block, but not the object, for example with do:
> x => do {
>   let a = 5;
>   return a*x;
> }
> AFAIK do expressions are not in ES6, but might be in ES7.

I don't follow -- this isn't a labeled statement. How would it be any
different from this?

x => {
  let a = 5;
  return a*x;

AFAIK nobody's proposed forbidding this form. How would do-expressions help
here? Sure, IIUC do-expressions would be a good solution for labeled
blocks, when they're available. But by es7 there's also plenty of time to
refactor the spec to allow some variant of /be's proposed
`WellLabeledStatement` grammar, which would allow well-formed labeled
statements w/o the do prefix.

Just to reiterate, I'm arguing that paren-wrapping should *still *be
required around object literal arrow bodies, now and forever. Anything else
would be impossibly confusing. But I can't see a reason to allow an
(accidentally) unwrapped object literal to parse. If it's not a
"well-labeled statement", it's surely a mistake.

 Marius Gundersen
> On 6 Jan 2015 19:42, "Brendan Eich" <brendan at mozilla.org> wrote:
>> Sorry, sent too soon.
>> Dean Landolt wrote:
>>> If it's too late to properly vet a change which narrowly excludes from
>>> arrow bodies any `LabeledStatement` that isn't a `WellLabeledStatement`,
>>> would it be feasible to simply exclude any `LabeledStatement` for now? I
>>> doubt there's much code in the wild that would be affected by this change
>>> -- certainly not yet. That'd buy plenty of time to add back proper support
>>> for `WellLabeledStatement` arrow bodies in es7.
>> The ES6 grammar has not been refactored per my old strawman. It has no
>> WellLabeledStatement non-terminal.
>> For ES6, we would need another production parameter to FunctionBody,
>> FunctionStatementList, and StatementList (at least) by which to restrict a
>> ConciseBody : { FunctionBody } such that the FunctionBody :
>> FunctionStatementList (via FunctionStatementList : StatementList[opt],
>> StatementList StatementListItem, etc.) doesn't start with a
>> LabelledStatement.
>> Cc'ing Allen and Waldemar for their thoughts.
>> /be
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150106/7f1c9f6b/attachment-0001.html>

More information about the es-discuss mailing list