function hoisting like var

Ingvar von Schoultz ingvar-v-s at comhem.se
Sun Jul 27 15:40:49 PDT 2008


Igor Bukanov wrote:
> 2008/7/26 Ingvar von Schoultz <ingvar-v-s at comhem.se>:
> 
>> I think all of these would be unambiguous:
>>
>>    {. code .}
> 
> {. not work since {.0; } is a valid ES3

Oops! True indeed.

>>    {: code :}
>>
>>    {| code |}
> 
> These 2 cases are indeed invalid  ES3.

I wonder if people would like using them.

>>    {[ code ]}
>>
>>    [[ code ]]
>>
>>    [ code ]
> 
> Any of this can be a valid ES3 code as [] always means an array literal.

I get the impression that disambiguation would be easy.

If [...] is preceded by =, or enclosed in ( ), or in some other
position where you can't have a block, it's a literal. If it's
a literal it must contain a comma-separated list of values, so
if the syntax doesn't match this, it's a block.

These two rules should provide very early disambiguation in
almost all cases.

As a last resort, consider that the whole point of a scoping
block is that you declare some names local within it. I don't
think you can write text that looks like such a declaration in
an array literal. (But I'm not yet sure about the ES4 syntax.)
So I think a final disambiguation rule could say that it's a
literal if the syntax inside matches a literal.

Checking a few cases, this seemed to work fine, so I felt that
just as {...} can be used both for literals and blocks, probably
[...] can be used too.

But my analysis was superficial. A thorough analysis becomes
interesting only if one of these becomes popular.

-- 
Ingvar von Schoultz

------- (My quirky use of capitals in code comes from my opinion that
reserved and predefined words should all start with lowercase, and
user-defined should all start with uppercase, because this will easily
and elegantly prevent a host of name-collision problems when things
like programming languages are upgraded with new labels.)




More information about the Es4-discuss mailing list