Skip to content

Aggressive JSX Do Expression Proposal #88

Open
@sebmarkbage

Description

@sebmarkbage

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:

  1. If it starts with {, then that is an ObjectLiteral, not a BlockStatement. (Ignoring leading comments and open parenthesis.)

  2. The completion value of a for, for...in, for...of, do or while loop is a newly created array with the completion value of each iteration in it. If it's a continue then the completion is undefined. 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.

  3. continue, break are not allowed at the top scope of these do-expressions. They're allowed in nested blocks but a break and continue 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 is undefined.

  4. return is not allowed inside a do-expression other than inside nested functions.

  5. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Proposal 2.0Proposals considerable for JSX 2.0

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions