Reserved word property access and line breaks

Peter van der Zee ecma at qfox.nl
Sat Aug 28 13:12:19 PDT 2010


The impact seems minimal (how often would this occur in the wild). I don't like
adding restrictions to the language for the sake of protecting a possible
defect, but I don't really see this as a problem since it's not exactly a best
practice to use reserved keywords as property names anyways ;) (re: CSFLD)

- peter

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


More information about the es-discuss mailing list