Arrow function syntax cover syntax

Erik Arvidsson erik.arvidsson at gmail.com
Sat Apr 7 13:40:51 PDT 2012


http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax

"This works because Expression is a cover grammar for
FormalParameterList, with Identifier primary expressions covering
formal parameter names, array and object literals for destructuring,
assignment for parameter default values, and spread for rest
parameters."

This does not work for rest parameter since ... is only allowed inside
array literals.

var tail = (x, ...xs) => xs;

This can of course be solved in numerous ways but it is not true that
the Expression is a cover grammar for FormalParameterList.

Another option is to allow ...expression in an expression which would
have the same semantics as a comma expression where the expression has
been spread:

...expression

desugars to

var $tmp = expression;
($tmp[0], $tmp[1], ..., $tmp[$tmp.length - 1])

but that is kind of useless.

-- 
erik


More information about the es-discuss mailing list