lexical for-in/for-of loose end

Allen Wirfs-Brock allen at wirfs-brock.com
Fri Feb 3 17:26:06 PST 2012


On Feb 3, 2012, at 4:26 PM, Jason Orendorff wrote:

> On 2/3/12 6:13 PM, Allen Wirfs-Brock wrote:
>> But I also have to validly (and hopefully reasonably) specify exactly what happens for the unrealistic use cases. There is a problem with your desugaring in that the evaluation of INIT isn't scoped correctly relative to V.
> Hmmm. I don't see the problem yet. I think it's scoped the way I intended it: INIT is evaluated in the enclosing environment; V isn't in scope.

Under the scoping rules TC39 has agreed to, the initializer of a let/const is always shadowed by the binding it is initializing:

{ 
   let i="outer";
   {
      let i=i;   // throws reference error because I is initialized
   }
}

Hence, for consistency, this also should throw in the same way 
{
    let i="outer";
    for (let i=i;;){}
}

You can tweak your desugaring to get this effect by changing the first part of it it:

{
    let V = INIT;
    let %tmp = V, %first = true;
    while (true) {
> 
> Anyway—all this should be easier to express in spec language than via desugaring, because in spec language you can give an environment a name. This makes it easier to just say what you mean. Whereas if you're using desugaring, scopes are *places*, so you have to very carefully say half of what you mean while standing in the right place to express the rest.

agreed

> 
> -j
> 



More information about the es-discuss mailing list