-
Notifications
You must be signed in to change notification settings - Fork 131
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 Implicit Do-Generator Semantics #98
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,20 +39,13 @@ interface JSXNamespacedName <: Expression { | |
JSX Expression Container | ||
------------------------ | ||
|
||
JSX adds empty "expression" type in order to allow comments in JSX text: | ||
The expression container node contains statements with the same grammar as a generator body. Also it has a flag to indicate if a yield is present in the body. Any expression used as attribute value or inside JSX text should is wrapped into expression container: | ||
|
||
```js | ||
interface JSXEmptyExpression <: Node { | ||
type: "JSXEmptyExpression"; | ||
} | ||
``` | ||
|
||
Any expression used as attribute value or inside JSX text should is wrapped into expression container: | ||
|
||
```js | ||
interface JSXExpressionContainer <: Node { | ||
interface JSXExpressionContainer <: Expression { | ||
type: "JSXExpressionContainer"; | ||
expression: Expression | JSXEmptyExpression; | ||
statements: [ Statement | Declaration ]; | ||
hasYield: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a requirement? Seems like the transform could figure that out if needed. I suppose it makes transform order and such a bit easier to deal with but for Babel I think it should be fine to visit the tree on demand. It's probably helpful to have though. We can just call it |
||
} | ||
``` | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ PrimaryExpression : | |
|
||
- JSXElement | ||
- JSXFragment | ||
- JSXGeneratorExpression | ||
|
||
__Elements__ | ||
|
||
|
@@ -95,7 +96,7 @@ JSXAttributes : | |
|
||
JSXSpreadAttribute : | ||
|
||
- `{` `...` AssignmentExpression `}` | ||
- `{` `...` JSXGeneratorExpression `}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't really work. You can't have a spread beginning a sequence of statements. I think for spread we'll need to leave it as Same thing in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it was a bit odd to define |
||
|
||
JSXAttribute : | ||
|
||
|
@@ -114,10 +115,15 @@ JSXAttributeValue : | |
|
||
- `"` JSXDoubleStringCharacters<sub>opt</sub> `"` | ||
- `'` JSXSingleStringCharacters<sub>opt</sub> `'` | ||
- `{` AssignmentExpression `}` | ||
- `{` JSXGeneratorExpression `}` | ||
- JSXElement | ||
- JSXFragment | ||
|
||
JSXGeneratorExpression : | ||
|
||
- [lookahead ∈ { `{` }] ObjectLiteral | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This checks for equality, which is unnecessary since Instead, use a negative lookahead on the |
||
- StatementList<sub>[+Yield]</sub> | ||
|
||
JSXDoubleStringCharacters : | ||
|
||
- JSXDoubleStringCharacter JSXDoubleStringCharacters<sub>opt</sub> | ||
|
@@ -157,8 +163,8 @@ JSXTextCharacter : | |
|
||
JSXChildExpression : | ||
|
||
- AssignmentExpression | ||
- `...` AssignmentExpression | ||
- JSXGeneratorExpression | ||
- `...` JSXGeneratorExpression | ||
|
||
__Whitespace and Comments__ | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declaration is a Statement in ESTree terminology (unlike the ES spec). Specifying both is superfluous.
We should probably go for backwards compatibility here. Lots of people can have transforms, linters and other things that depend on this.
We could have a flag that switches between the statement list form or expression form depending on if there are more than one expression. Similar to how
ArrowFunctionExpression
works.