On Jan 7, 2015, at 1:23 PM, Brendan Eich wrote:
> Allen Wirfs-Brock wrote:
>> On Jan 6, 2015, at 5:34 PM, Gary Guo wrote:
>>
>>> I found that even without shorthand, the object literal can still be
>>> ambiguous with block.
>>
>> Yes, but not in the context of a ConciseBody of an ArrowFunction.
>>
>> The grammar for ConciseBody
>> (http://people.mozilla.org/~jorendorff/es6-draft.html#sec-arrow-function-definitions
>>
>> <http://people.mozilla.org/%7Ejorendorff/es6-draft.html#sec-arrow-function-definitions>
>> ) ensures that there is no ambiguity. If a ConciseBody starts with a { then
>> it must parse as either a well-formed bracketed FunctionBody or as a syntax
>> error.
>>
>> There is no guessing. { means statements follow rather than an expression.
>
> Indeed. Perhaps Gary meant less formal ambiguity, as Caitlin did earlier in
> thread -- in which case we could future-proof or perhaps just help people by
> proscribing { L: 42 } from being parsed as a ConciseBody. I'm curious to know
> what you think about this idea. It seems best done with parametric
> productions, but I haven't worked it out yet.
Certainly is plausible. I suspect there might be a couple places in the ES
grammar where we could replace lookahead restrictions with parameterization.
I'm less sure whether there is a reason to prefer one over the other.
ObjectLiteral is already doing double duty covering ObjectAssignmentPattern.
so this would be even more complexity in this area of the grammar.
Finally, I'm sort of on the side that this may not be so good for programmers.
The rule, "if it starts with a { its a function body" is simple to teach and
remember. Adding "except if the first thing is a labeled expression statement"
(or whatever) is more difficult to explain and remember. More likely then not,
all that many programmers would take away is "there are some special cases here
that I don't really remember so I need to be really careful". I'm not sure
that is an improvement over the status quo.
Allen
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss