RFE: Allow newline when returning an anonymous object

cowwoc cowwoc at bbs.darktech.org
Wed May 28 11:39:58 PDT 2014

On 28/05/2014 2:33 PM, Oliver Hunt wrote:
>> On May 28, 2014, at 11:23 AM, cowwoc <cowwoc at bbs.darktech.org 
>> <mailto: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

Don't we use a semicolon to denote the end of an expression context? 
Perhaps I'm missing something, but I see no ambiguity in the example you 
gave. I expect:

   return {};



to return an object literal, whereas:

   return; {}



denote a return expression followed by a block.

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

More information about the es-discuss mailing list