From aac60d5af31fc5122ab91e4c6f924f2ca553ba94 Mon Sep 17 00:00:00 2001 From: Clement Hoang Date: Wed, 27 Sep 2017 16:11:27 -0700 Subject: [PATCH 1/5] Add proposed fragment changes --- AST.md | 6 ++++-- README.md | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/AST.md b/AST.md index 723cdcf..4cad09e 100644 --- a/AST.md +++ b/AST.md @@ -73,12 +73,13 @@ Any JSX element is bounded by tags — either self-closing or both opening a ```js interface JSXBoundaryElement <: Node { name: JSXIdentifier | JSXMemberExpression | JSXNamespacedName; + isFragment: boolean; } interface JSXOpeningElement <: JSXBoundaryElement { type: "JSXOpeningElement", attributes: [ JSXAttribute | JSXSpreadAttribute ], - selfClosing: boolean; + selfClosing: boolean; // if this is true, isFragment must be false, and vice-versa } interface JSXClosingElement <: JSXBoundaryElement { @@ -133,7 +134,8 @@ interface JSXElement <: Expression { type: "JSXElement", openingElement: JSXOpeningElement, children: [ JSXText | JSXExpressionContainer | JSXSpreadChild | JSXElement ], - closingElement: JSXClosingElement | null + closingElement: JSXClosingElement | null, + isFragment: boolean; } ``` diff --git a/README.md b/README.md index 040a7aa..c898a3c 100644 --- a/README.md +++ b/README.md @@ -51,10 +51,12 @@ JSXElement :
 JSXSelfClosingElement : - `<` JSXElementName JSXAttributesopt `/` `>` + (isFragment cannot be true if selfClosing) JSXOpeningElement : - `<` JSXElementName JSXAttributesopt `>` + (no JSXAttributes allowed if isFragment is true) JSXClosingElement : From 448fea4a6ef86916e8fa8f2887458fc703e34063 Mon Sep 17 00:00:00 2001 From: Clement Hoang Date: Thu, 28 Sep 2017 12:42:58 -0700 Subject: [PATCH 2/5] Use explicit JSXFragment node instead of flags in JSXElement --- AST.md | 36 ++++++++++++++++++++++++++++++------ README.md | 14 ++++++++++++-- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/AST.md b/AST.md index 4cad09e..f579c8f 100644 --- a/AST.md +++ b/AST.md @@ -73,13 +73,12 @@ Any JSX element is bounded by tags — either self-closing or both opening a ```js interface JSXBoundaryElement <: Node { name: JSXIdentifier | JSXMemberExpression | JSXNamespacedName; - isFragment: boolean; } interface JSXOpeningElement <: JSXBoundaryElement { type: "JSXOpeningElement", attributes: [ JSXAttribute | JSXSpreadAttribute ], - selfClosing: boolean; // if this is true, isFragment must be false, and vice-versa + selfClosing: boolean; } interface JSXClosingElement <: JSXBoundaryElement { @@ -127,15 +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: ```js interface JSXElement <: Expression { type: "JSXElement", openingElement: JSXOpeningElement, - children: [ JSXText | JSXExpressionContainer | JSXSpreadChild | JSXElement ], - closingElement: JSXClosingElement | null, - isFragment: boolean; + 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: + +```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"; } ``` diff --git a/README.md b/README.md index c898a3c..4da5671 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ _JSX extends the PrimaryExpression in the [ECMAScript 6th Edition (ECMA-262)](ht PrimaryExpression : - JSXElement +- JSXFragment __Elements__ @@ -51,17 +52,26 @@ JSXElement :
 JSXSelfClosingElement : - `<` JSXElementName JSXAttributesopt `/` `>` - (isFragment cannot be true if selfClosing) JSXOpeningElement : - `<` JSXElementName JSXAttributesopt `>` - (no JSXAttributes allowed if isFragment is true) JSXClosingElement : - `<` `/` JSXElementName `>` +JSXFragment : + +- JSXOpeningFragment JSXChildrenopt JSXClosingFragment + +JSXOpeningFragment : + +- `<>` + +JSXClosingFragment : +- `` + JSXElementName : - JSXIdentifier From f317675e1e2fe1c9fd4967f81bc3dd140869098e Mon Sep 17 00:00:00 2001 From: Clement Hoang Date: Thu, 28 Sep 2017 14:54:45 -0700 Subject: [PATCH 3/5] Remove JSXOpeningFragment and JSXClosingFragment from authoritative spec --- README.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/README.md b/README.md index 4da5671..64e22c2 100644 --- a/README.md +++ b/README.md @@ -63,14 +63,7 @@ JSXClosingElement : JSXFragment : -- JSXOpeningFragment JSXChildrenopt JSXClosingFragment - -JSXOpeningFragment : - -- `<>` - -JSXClosingFragment : -- `` +- <> JSXChildrenopt JSXElementName : From a3bd36da59a941adbc3ac8b8055e91f3f9a07dc3 Mon Sep 17 00:00:00 2001 From: Clement Hoang Date: Thu, 28 Sep 2017 16:30:12 -0700 Subject: [PATCH 4/5] Make fragment syntax tokens more explicit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 64e22c2..14435b9 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ JSXClosingElement : JSXFragment : -- <> JSXChildrenopt +- `<` `>` JSXChildrenopt `<` `/` `>` JSXElementName : From 6bf12198152ac9bced9949006678f651102f277d Mon Sep 17 00:00:00 2001 From: Clement Hoang Date: Fri, 29 Sep 2017 10:48:12 -0700 Subject: [PATCH 5/5] Make wording less awkward --- AST.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AST.md b/AST.md index 3af652b..8400fb8 100644 --- a/AST.md +++ b/AST.md @@ -126,7 +126,7 @@ interface JSXText <: Node { JSX Element ----------- -JSX element itself consists of opening element, list of children and optional closing element: +JSX element consists of opening element, list of children and optional closing element: ```js interface JSXElement <: Expression { @@ -140,7 +140,7 @@ interface JSXElement <: Expression { JSX Fragment ------------ -JSX fragment itself consists of an opening fragment, list of children, and closing fragment: +JSX fragment consists of an opening fragment, list of children, and closing fragment: ```js interface JSXFragment <: Expression {