Nannying (was: Array comprehension syntax)

Kevin Smith khs4473 at gmail.com
Mon Sep 24 12:25:30 PDT 2012


>
> Here's another program I think we should reject, for the same reason:
>
>    var titles = books.map(b => {title: b.title});
>
> The behavior here is really astonishing.  It's hard to see how the
> developer is supposed to figure out what's wrong.  I'm willing to take
> on some implementation complexity to head off this kind of
> frustration.
>
>
> I agree that this is a real hazard. I think eliminating it requires two
> token look-ahead.  If that is ok, then we could specify
>
> *ConciseBody **:*
>
> [lookahead  ∉ { *{* }]* AssignmentExpression
> **{*[lookahead  ∉ { *IdentifierName* }] [lookahead  ∉ { *:*}] *FunctionBody
> **}*
>

The hazard would still be there in other (admittedly less frequent) forms,
though:

    var books = isbns.map(isbn => { isbn });

But this is the kind of thing that linters are really good at (pointing out
constructs that *might* be errors).

Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120924/357ef349/attachment-0001.html>


More information about the es-discuss mailing list