Closed littledan closed 8 years ago
I feel like return continue
and => continue
are more conservative and thus more likely to be acceptable to people. I think the distinction between expr and statement forms can also get confusing.
However, option B does have the benefit of working better with ternary without requiring a complicated grammar.
(Note that option B would need to also include MemberExpression TemplateLiteral
).
Now that I've gone over the options, I don't think the latter option is that onerous, and it has the huge advantage of keeping continue right before the call. Unless I'm missing something obvious, grammatically, then I think ReturnExpression : continue MemberExpression Arguments
and friends is the way to go. I've took a stab at defining this grammar here: https://tc39.github.io/proposal-ptc-syntax.
I find Option B more natural, because tail position is a property of a (sub)expression, not of the entire return statement.
I've took a stab at defining this grammar here: https://tc39.github.io/proposal-ptc-syntax.
In that stab, I think that the ReturnExpression production would be better named TailCallExpression.
@claudepache Agreed, just pushed an update for that.
Seems like the spec has stabilized on "yes".
I see two ways that the
return continue
syntax could be specified:Option A
There are two fixed special forms,
return continue
and=> continue
. These evaluate whether the following expression contains a tail call in the same way as in ES2015.Option B
continue
MemberExpression Arguments is a new way of making a function call be a tail call. It can only be used in expression contexts--in statement context, it is still a labelled continue, with the arguments forming a SyntaxError. Syntactically, each particular tail call has to be marked--so a ternary operator would have its individual branches marked. It would be an Early Error to usecontinue
in a place which is not in tail context.I haven't figured out how these fit into the grammar or spec of PTC/STC yet, so these are just vague ideas at the moment. Note that they would also both apply for syntax like
return ^foo(x)
, but not for!return foo(x)
or function-level syntax.