three small proposals: the bikeshed cometh!

Mark S. Miller erights at google.com
Thu Apr 29 15:48:57 PDT 2010


On Thu, Apr 29, 2010 at 3:32 PM, Brendan Eich <brendan at mozilla.com> wrote:

> On Apr 29, 2010, at 3:16 PM, Mark S. Miller wrote:
>
> On Thu, Apr 29, 2010 at 2:39 PM, Brendan Eich <brendan at mozilla.com> wrote:
>
>> Really, methinks you guys protest too much. In particular Mike's "all new
>> productions that introduce a new keyword should be restricted" is simply
>> wrong for "let".
>>
>
> Btw, regarding "let", ASI, and Dave's recent "let" expression proposal <
> http://wiki.ecmascript.org/doku.php?id=strawman:let_expressions>, how
> should
>
>     let () { => foo }
>     (3, 4)
>
> parse? Is it a function call?
>
>
> As far as I can tell, this is covered by ECMA-262 7.9.2:
>
> The source
> *
> *
> *  a = b + c*
> *  (d + e).print()*
>
> is *not *transformed by automatic semicolon insertion, because the
> parenthesised expression that begins the second
> line can be interpreted as an argument list for a function call:
> *
> *
> *  a = b + c(d + e).print()*
>


Formally, that makes sense. But given that all the other

    <keyword> ... "{" ... "}"

productions, if they occur at the beginning of a statement, end with the
"}", I think this reading of the let expression may be confusing. What if we
adopt the same (admittedly unpleasant) rule we already have for the
"function" keyword: It can't begin an expression statement. If it occurs at
the beginning of a statement, it is a statement. If you want a let
expression in that position, surround it with parens.

In other words, better to be unpleasantly consistent than to be
inconsistent. (Please no "small mind hobgoblins" ;).)



> In the circumstance that an assignment statement must begin with a left
> parenthesis, it is a good idea for the
> programmer to provide an explicit semicolon at the end of the preceding
> statement rather than to rely on automatic
> semicolon insertion.
>
>
> As David-Sarah Hopwood pointed out a while ago, there's no error to
> correct.
>
> I'm assuming here that let () { => foo } will be a PrimaryExpression. The
> always-braced body avoids reduce-reduce conflicts Waldemar pointed out in
> connection with ES4's unbracketed let expression body.
>
> /be
>
>


-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20100429/641c0afc/attachment.html>


More information about the es-discuss mailing list