return when desugaring to closures

David-Sarah Hopwood david.hopwood at
Mon Oct 13 08:05:20 PDT 2008

Mark S. Miller wrote:
> On Sun, Oct 12, 2008 at 7:55 PM, David-Sarah Hopwood
> <david.hopwood at> wrote:
>> In ES3.1, this will mean that they normally require braces whenever a
>> body can introduce variables. There are two classes of exceptions,
>> shown by these examples:
>>  a) while (...) foo: var x = ...;
>>  b) while (...) for (var x = ...; ...; ...) {}
>> I think these are bugs. a) can certainly be disallowed. There might
>> possibly be existing code that is relying on b), confusing though it
>> is, but it can be disallowed in strict mode at least.
> ES3.1 will disallow #a because a LabelledStatement can only contain a
> SubStatement. A variable declaration is a Statement but not a
> SubStatement.

Note that although there is currently no plausible use for

  { foo: let x = ...; }

because expressions cannot 'break' or 'continue' to a label
outside the expression, that reason will no longer hold if/when
we add lambdas. In that case "..." might contain (after expansion)
a lambda that says "break foo;" or "continue foo;". But that doesn't
really cause any problem since,
 - if the let is written explicitly by the programmer, it's easy
   enough to add extra braces in this (presumably rare) case;
 - if the let is introduced by an expansion, the expansion should
   include braces around it if it is intended to be a SubStatement.

<snip contribution added by cat walking on keyboard>

[Reminder to self: In order for Jacaranda to continue to be a subset
of ES3.1, I will have to change it to reject "label: var ...",
which was allowed in draft 0.3.]

> Your point about #b is interesting. I do not know if it has previously
> been raised.

Actually the while loop is a red herring in that example:
"for (var ...)" implicitly introduces a block whether or not it
is a substatement. This is a wart of C++/C99/Java syntax that
we have to live with, since too much code relies on it.

David-Sarah Hopwood

More information about the Es-discuss mailing list