Description
This is my current take on #39
Do expressions in JS are moving quite slowly because it's not very pretty but there seems to be a direction that is sort of shaping up and compromises that occur. JSX users are also the ones that want this the most.
Therefore, I'm proposing that we change up how we do things a bit and instead of pursuing the JS route first, we become an early experiment surface for a more aggressive proposal.
The major rule of this proposal is that we should be backwards compatible with existing JSX for anything but edge cases that nobody would write. That helps us avoid a much larger conversation of #65.
The proposal that all JSX containers are implicit do-expressions with a few tweaks:
-
If it starts with
{
, then that is anObjectLiteral
, not aBlockStatement
. (Ignoring leading comments and open parenthesis.) -
The completion value of a
for
,for...in
,for...of
,do
orwhile
loop is a newly created array with the completion value of each iteration in it. If it's acontinue
then the completion isundefined
. The semantics of this doesn't need to be specified in this spec but it needs to have the syntactic mechanisms in the spec to allow implementations and ASTs to be able to do this in a reasonable way. -
continue
,break
are not allowed at the top scope of these do-expressions. They're allowed in nested blocks but abreak
andcontinue
inside a nested block is not allowed to reference a label outside the inner most do-expression. If you break out of the last statement, that completion value isundefined
. -
return
is not allowed inside a do-expression other than inside nested functions. -
throw
expressions are allowed per https://github.com/rbuckton/proposal-throw-expressions but not specified separately.
Are there any other tweaks we'd have to do to remain backwards compatible with the expression form?