Reserved word property access and line breaks

Oliver Hunt oliver at apple.com
Tue Aug 24 15:19:01 PDT 2010


It does seem reasonable to disallow new lines in that context.

--Oliver

On Aug 24, 2010, at 1:53 PM, Allen Wirfs-Brock wrote:

> 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
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list