(Almost) everything is expression

Mike Samuel mikesamuel at gmail.com
Fri Nov 11 05:59:58 PST 2011

2011/11/11 David Herman <dherman at mozilla.com>:
>> Brendan and Dave mention explicit semicolon. Yes, it's seems so by the grammar (though, have to check more precisely), but it can be acceptable price.
> It's a serious price, though. Today if I write:
>    if (q) { ... }
>    else { ... }
>    (f())
> then ASI kicks in after the else body. If we make if-statements into expressions, then either the above becomes a single expression, which is a serious and subtle backwards-incompatible change, or we define lookahead restrictions on ExpressionStatement, and introduce a refactoring hazard:
>    x = if (q) { ... }
>        else { ... }
>    (f())                 // oops, this is now a parameter list on the RHS of the assignment!
> I'm not positive, but that seems like a serious issue to me.

There seem to be two separable issues here:
(1) being able to use conditions, loops, etc. where expressions can occur.
(2) return elision

I also find this a serious problem for (1) and there are less serious
changes of behavior when the following token is ('[', '+', '-').

It can't possibly be changed by mucking with precedence levels or
reworking CallExpression because of

new if (c) s1 else s2

but if instead of changing PrimaryExpression, you change the grouping
operator from
    '(' <Expression> ')'
    '(' (lookahead not in '{', 'function') <StatementList> ')'
or even with let-scoped functions declarations
    '(' (lookahead not in '{', 'function') <Program> ')'
and change semicolon insertion to allow insertion before a ')' which
should not affect for(;;).

>> Though, it can be visually _really_ ambiguous with object initialisers in case of using labels inside the block:
> A JS grammar needs to be formally unambiguous, so it requires very careful specification. Syntax design for JS is very tricky.
>> Nope, have to think more on this...
> You might want to take a look at this:
>    http://wiki.ecmascript.org/doku.php?id=strawman:block_vs_object_literal
> Dave
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

More information about the es-discuss mailing list