Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: React Expressions with Explicit Generator Expression Semantics #99

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions AST.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,22 @@ interface JSXEmptyExpression <: Node {
}
```

Any expression used as attribute value or inside JSX text should is wrapped into expression container:
The expression container node contains statements with the same grammar as a generator body. Also it has a flag to indicate whether it is an expression. Any expression used as attribute value or inside JSX text should is wrapped into expression container:

```js
interface JSXExpressionContainer <: Node {
type: "JSXExpressionContainer";
expression: Expression | JSXEmptyExpression;
expression: Expression | JSXEmptyExpression | JSXBlockStatement;
isExpression: boolean;
}
```

From `BlockStatement`, this inherits `body: [ Statement ];`.

```js
interface JSXBlockStatement <: BlockStatement {
type: "JSXStatementList";
generator: boolean;
}
```

Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ PrimaryExpression :

- JSXElement
- JSXFragment
- JSXGeneratorExpressionContainer

__Elements__

Expand Down Expand Up @@ -115,9 +116,21 @@ JSXAttributeValue :

- `"` JSXDoubleStringCharacters<sub>opt</sub> `"`
- `'` JSXSingleStringCharacters<sub>opt</sub> `'`
- `{` AssignmentExpression `}`
- JSXGeneratorExpressionContainer
- JSXElement
- JSXFragment

JSXGeneratorExpressionContainer :
- `*` `{` JSXGeneratorExpression<sub>opt</sub> `}`

JSXGeneratorExpression :
- ObjectLiteral
- FunctionExpression
- ClassExpression
- GeneratorExpression
- AsyncFunctionExpression
- FunctionBody<sub>[+Yield, ~Await, ~Return]</sub>
Copy link
Contributor

@sebmarkbage sebmarkbage Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FunctionBody is ambiguous since it also includes BlockStatement, FunctionDeclaration, ClassDeclaration, GeneratorExpression and AsyncFunctionDeclaration.

We need to exclude them from the list. Either by defining our own statement list explicitly, or by excluding these by some kind of lookahead.

E.g. an explicit list could look something like this:

JSXStatementList:
  JSXStatementListFirstItem StatementList[opt]

JSXStatementListFirstItem:
  LexicalDeclaration
  VariableStatement
  ExpressionStatement
  IfStatement
  BreakableStatement
  BreakStatement
  WithStatement
  LabelledStatement
  ThrowStatement
  TryStatement
  DebuggerStatement

(This also highlights the maintenance cost associated with forking the language.)

Copy link
Contributor Author

@clemmy clemmy Nov 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, this is a problem with the other proposal as well, and I'm not sure there's a way to lower the maintenance cost by a significant amount. Either way, we'll need to keep adding to lookaheads or JSXStatementListFirstItem for new ECMAScript features. For now I'll just go with the lookahead approach - we just can't have {, class, async, function, and do right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering what to do for (...


JSXDoubleStringCharacters :


- JSXDoubleStringCharacter JSXDoubleStringCharacters<sub>opt</sub>
Expand Down Expand Up @@ -145,15 +158,17 @@ JSXChild :
- JSXText
- JSXElement
- JSXFragment
- JSXGeneratorExpressionContainer
- `{` JSXChildExpression<sub>opt</sub> `}`

JSXText :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need a disambiguator in JSXText for * {. For example, you can exclude * from JSXTextCharacter and explicitly allow it in JSXText for certain contexts. E.g. by a look ahead.

Note that JSXGeneratorExpressionContainer is defined in terms of two token so spaces, comments etc. are allowed between. E.g. this is still a generator:

<div>* /* hello */ { yield 1; }</div>


- JSXTextCharacter JSXText<sub>opt</sub>
- [lookahead &#8713; { `{` }] `*` JSXText<sub>opt</sub>

JSXTextCharacter :

- SourceCharacter __but not one of `{`, `<`, `>` or `}`__
- SourceCharacter __but not one of `*`, `{`, `<`, `>` or `}`__

JSXChildExpression :

Expand Down