return when desugaring to closures

Waldemar Horwat waldemar at google.com
Mon Oct 20 11:43:35 PDT 2008


Eric Suen wrote:
> I think top-down parser has no issue to parse following code:
> 
> function() {
> }();
> 
> but this is not a valid statement because:
> 
> ExpressionStatement ::= [lookahead ! {{, function}] Expression ;

There is a good reason for that.  It's because of semicolon insertion.  You'd break things if you tried to "fix" it.

Folks write code such as:

function f() {
  ...
}

(a + b)....

and this would turn the expression into a function call.

Another issue is that the function name (the "f" in this case) does entirely different things depending on whether it's a function expression or a function definition.

    Waldemar


More information about the Es-discuss mailing list