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

Add proposed fragment changes #93

Merged
merged 6 commits into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
32 changes: 29 additions & 3 deletions AST.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,40 @@ interface JSXText <: Node {
JSX Element
-----------

Finally, JSX element itself consists of opening element, list of children and optional closing element:
JSX element itself consists of opening element, list of children and optional closing element:

Choose a reason for hiding this comment

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

A JSX element consists of maybe?


```js
interface JSXElement <: Expression {
type: "JSXElement",
openingElement: JSXOpeningElement,
children: [ JSXText | JSXExpressionContainer | JSXSpreadChild | JSXElement ],
closingElement: JSXClosingElement | null
children: [ JSXText | JSXExpressionContainer | JSXSpreadChild | JSXElement | JSXFragment ];
closingElement: JSXClosingElement | null;
}
```

JSX Fragment
------------

JSX fragment itself consists of an opening fragment, list of children, and closing fragment:

Choose a reason for hiding this comment

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

Same as above. Feels like the grammar is weird in these.


```js
interface JSXFragment <: Expression {
type: "JSXFragment";
openingFragment: JSXOpeningFragment;
children: [ JSXText | JSXExpressionContainer | JSXSpreadChild | JSXElement | JSXFragment ];
closingFragment: JSXClosingFragment;
}
```

```js
interface JSXOpeningFragment <: Node {
type: "JSXOpeningFragment";
}
```

```js
interface JSXClosingFragment <: Node {
type: "JSXClosingFragment";
}
```

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ _JSX extends the PrimaryExpression in the [ECMAScript 6th Edition (ECMA-262)](ht
PrimaryExpression :

- JSXElement
- JSXFragment

__Elements__

Expand All @@ -60,6 +61,10 @@ JSXClosingElement :

- `<` `/` JSXElementName `>`

JSXFragment :

- <> JSXChildren<sub>opt</sub> </>
Copy link
Contributor

@sebmarkbage sebmarkbage Sep 28, 2017

Choose a reason for hiding this comment

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

This should use the ` character around each token with a space between.

- `<` `>` JSXChildren<sub>opt</sub> `<` `/` `>`

So the formatting comes out like this:

  • < > JSXChildrenopt < / >

The point of this is because we build this on top of the normal tokenizing in JavaScript. These individual tokens already exist but there's no <> token or </> token so when building a parser, you have to parse these individually. It also means that it is ok to have whitespace or even comments(!) between them.

E.g. this is valid:

let fragment = <>
< // comment
/ /* another comment */ >;


JSXElementName :

- JSXIdentifier
Expand Down