(x) => {foo: bar}

Brendan Eich brendan at mozilla.org
Mon Jan 5 11:54:44 PST 2015

Caitlin Potter wrote:
> The strawman changes to the grammar are still ambiguous :(
> `() => {}` -> noop or Object or SyntaxError? If SyntaxError, ...why?

No, the strawman addresses this: "An empty pair of braces |*{}*| other 
than at start of /Statement/ is an /ObjectLiteral/." The grammar is 
unambiguous. Notice the meta-? in the first production RHS below, and 
the non-empty-producing nature of the second:

     { UnlabeledStatementFirstList? }
     { WellLabeledStatement StatementList? }

     UnlabeledStatementFirstList Statement

The final piece of the puzzle is here:

We retain the |[lookahead ∉ {*{*, *function*}]| restriction in 
/ExpressionStatement/. At the start of a statement, |*{*| can be the 
start of a block only, never an object literal.

> I think hacking around this would not get rid of the footgun, but 
> would just make it more complicated to understand the footgun, personally.

You mean replace the footgun with a smaller one, maybe one so small it 
doesn't matter. Saying that the proposal doesn't get rid of the footgun 
means it still remains impossible to write x => {p: x} and not get what 
Frankie and others want: an arrow returning an object. But the proposal 
does fix that footgun.

How often do you really want an empty object instead of a block with no 


More information about the es-discuss mailing list