RFE: Allow newline when returning an anonymous object

Oliver Hunt oliver at apple.com
Wed May 28 11:33:36 PDT 2014


> On May 28, 2014, at 11:23 AM, cowwoc <cowwoc at bbs.darktech.org> wrote:
>> 
>> if (foo)
>>   return
>> {
>> L: print(something)
>> }
>> 
>> The only way to disambiguate this in the general case is to have a rule
>> such as 
>> <no newline>
>> to allow us to be sure that the opening brace is in an expression context
>> and not a statement.
>> 
>> --Oliver
> 
> Hi Oliver,
> 
> Excuse my ignorance, but can you explain (or point me to a layman
> explanation) of the difference between the two forms?
> 

I'm not sure what you mean by two forms - i'm assuming that you mean that you're interpreting the {}'s in both

return {}

and

return
{}

As being object literals, when in fact the second is a return statement, followed by a  block statement.

This ambiguity is why the opening brace is only consider an object literal if we are already in an expression context.  If you are not in an expression context, you must be starting a statement, and so the open brace is the start of a block statement.

What you're asking for is grammatically ambiguous in a way that would potentially break existing content, and (generally) leads to really interesting parsing behaviour.

--Oliver

> Thanks,
> Gili
> 
> 
> 
> --
> View this message in context: http://mozilla.6506.n7.nabble.com/RFE-Allow-newline-when-returning-an-anonymous-object-tp316480p316482.html
> Sent from the Mozilla - ECMAScript 4 discussion mailing list archive at Nabble.com.
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140528/b0f1d279/attachment.html>


More information about the es-discuss mailing list