Consider the following JavaScript code fragment:

var x=foo.
if (a>b)  -bar;

If this showed up in real code, it would probably be either as a typo where 
either the actual property name for foo was left off or because of a mental 
lapse by an old Smalltalk programmer who was used to using . instead of ; to 
terminate statements. Regardless, it will validly parse identically to the 
following single line formulation:

var x=foo.if(a>b)-bar;

The ES5 grammar for a dotted property access is:

CallExpression ::
    CallExpression . IdentifierName

Where IdentifierName includes all possible identifiers including reserved 
words.  The above confusion could have been avoided if we had instead defined 
things as:

CallExpression ::
    CallExpression . Identifier
    CallExpression . [no LineTerminator here] ReservedWord

Is this the grammar we should have used for ES5?  It's too late to make this 
change in the ES5 spec.  but if we had consensus that this is how it should be 
specified in Harmony we might also get the emerging ES5 implementations to also 
follow this interpretations.

Thoughts?  It's kind of hooky to have semi-arbitrary restrictions on line 
terminator placement.  But we already have them in order to make semi-colon 
insertion more sane and arguably such restrictions reasonably go hand-in-hand 
with allowing context sensitive use of reserved words.

Allen
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to