On Apr 17, 2011, at 9:09 AM, David Herman wrote: > * functions with expression bodies > > This was proposed for ES4 and implemented in SpiderMonkey. I believe there > are some unfortunate ambiguities in the grammar that came up, and I think > they've been treated as moribund. But I love them, and would love it if we > could find a way to bring them back in a way that didn't break the grammar.
The counterexample Waldemar gave, adjusted to use a function with expression body instead of a let expression, is worth repeating: function f() {return "f"} var x = 3; alert(function (a) a ? f : x++(1)); /*^^^^^^^^^^^^^^^^^^^^^^^^*/ The alert should show "f". Note that the call grammar: CallExpression : MemberExpression Arguments CallExpression Arguments does not parse an unparenthesized AssignmentExpression (the function with expression body's body non-terminal, in ES4 and what we implemented) as the "callee" part of the right-hand side (underlined with ^^^ above). But it does parse a PrimaryExpression, which includes function expressions, which loops back to the AssignmentExpression at the end. The rule is "You can't have an AssignmentExpression terminating a PrimaryExpression". Note that this has nothing to do with ASI. As I wrote at the time, this problem could be patched by making the body expression nonterminal be high-precedence, or else require parens. That seemed not worth the trouble to me at the time, and now I really would rather work on sharp functions, or arrow functions, to relieve the cost of 'return' as well as 'function'. At the last TC39 meeting, Waldemar objected to implicit return of a (reformed) completion value. I have an idea to address that, which I'll post in a new thread. /be _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss