(x) => {foo: bar}

Caitlin Potter caitpotter88 at gmail.com
Mon Jan 5 11:49:53 PST 2015


The strawman changes to the grammar are still ambiguous :(

`() => {}` -> noop or Object or SyntaxError? If SyntaxError, ...why?

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


On Mon, Jan 5, 2015 at 2:46 PM, Domenic Denicola <d at domenic.me> wrote:

> What do you think the chances of this are in ES7+? That is, how
> backward-compatible is this change? The linked strawman doesn't seem to
> touch on `() => { foo: bar }` as a back-compat hazard. Do you feel hopeful?
>
> -----Original Message-----
> From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of
> Brendan Eich
> Sent: Monday, January 5, 2015 14:41
> To: Calvin Metcalf
> Cc: es-discuss
> Subject: Re: (x) => {foo: bar}
>
> See
>
> http://wiki.ecmascript.org/doku.php?id=strawman:block_vs_object_literal
>
> This could be done, but not for ES6. Sorry I didn't push this harder,
> earlier.
>
> /be
>
> Calvin Metcalf wrote:
> > this seems like a footgun and has tripped people up in the wild
> > https://twitter.com/jankrems/status/544645776518184960
> >
> > On Mon Jan 05 2015 at 2:05:52 PM Caitlin Potter
> > <caitpotter88 at gmail.com <mailto:caitpotter88 at gmail.com>> wrote:
> >
> >     > In the implementations I checked, this is actually allowed, but
> >     it's parsed as a label instead of what you may expect at first
> >     glance (an object).
> >
> >     For it to be a concise body, you need to change it to `let f = (x)
> >     => ({foo: bar});`. Otherwise, it's like a regular function body.
> >
> >     On Mon, Jan 5, 2015 at 2:02 PM, Frankie Bagnardi
> >     <f.bagnardi at gmail.com <mailto:f.bagnardi at gmail.com>> wrote:
> >
> >         let f = (x) => {foo: bar};
> >
> >         In the implementations I checked, this is actually allowed,
> >         but it's parsed as a label instead of what you may expect at
> >         first glance (an object).
> >
> >         Is there any reason this is allowed?  If there's no reason
> >         other than to match function(){}, this should be a syntax
> >         error, in my opinion.
> >
> >         A potentially easier and wider reaching solution here would be
> >         to restrict labels in strict mode to demand a possible
> >         break/continue, else it's a syntax error.  The only area I'd
> >         be concerned about compatibility is low level generated
> >         JavaScript.
> >
> >         Thoughts?
> >
> >         _______________________________________________
> >         es-discuss mailing list
> >         es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
> >         https://mail.mozilla.org/listinfo/es-discuss
> >
> >
> >     _______________________________________________
> >     es-discuss mailing list
> >     es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
> >     https://mail.mozilla.org/listinfo/es-discuss
> >
> > _______________________________________________
> > es-discuss mailing list
> > es-discuss at mozilla.org
> > https://mail.mozilla.org/listinfo/es-discuss
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
> _______________________________________________
> 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/20150105/cf8e1eaa/attachment-0001.html>


More information about the es-discuss mailing list