-
Notifications
You must be signed in to change notification settings - Fork 784
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
Support JSX Syntax #1467
Comments
Why? This isn't even standards track. |
Given the current modular state of the code base, I believe it is time for Esprima to participate in the React.js world without a significant additional maintenance burden! |
If it was user extensible, esprima wouldn't have to participate, and more importantly wouldn't have to take on that maintenance burden. |
After considering a few different strategies, I've decided that I can take the risk of implementing it in Esprima, with the future possibilities of subsequent refactoring, a detached plug-in, or other types of improvements. |
A notable difference between Flow and the old esprima-fb is the use of Flow: [ { type: 'JSXText', value: ' ', raw: ' ' },
{ type: 'JSXElement',
openingElement:
{ type: 'JSXOpeningElement',
name: [Object],
selfClosing: false,
attributes: [] },
closingElement: { type: 'JSXClosingElement', name: [Object] },
children: [ [Object] ] },
{ type: 'JSXText', value: ' ', raw: ' ' } ] old esprima-fb: [ { type: 'Literal', value: ' ', raw: ' ' },
{ type: 'JSXElement',
openingElement:
{ type: 'JSXOpeningElement',
name: [Object],
selfClosing: false,
attributes: [] },
closingElement: { type: 'JSXClosingElement', name: [Object] },
children: [ [Object] ] },
{ type: 'Literal', value: ' ', raw: ' ' } ] Which one shall I follow @sebmarkbage @jeffmo? |
The ESTree compatible extension spec for JSX says https://github.com/facebook/jsx/blob/master/AST.md#jsx-element I believe it is what Babylon/Acorn does. @jeffmo Should we update Flow to be consistent with this ESTree extension? |
@sebmarkbage Overloading Literal even more than it already is sounds like a bad idea. Also, I believe the babel AST split apart the Literal node long ago. |
Babel has switched from I am also leaning towards I can open an ESTree issue if we prefer the discussion to happen over there. |
Example: esprima.parse('<div>Hello</div>', { jsx: true }); Fixes jquery#1467
Asking here because couldn't find answer anywhere on the Internet: how to parse today using esprima with JSX support enabled? |
@Bartq This is not part of any release yet. To watch for a release, subscribe yourself to a service like https://libraries.io/npm/esprima. |
Optionally, Esprima should be able to consume JSX syntax: https://facebook.github.io/jsx/. See also https://github.com/facebook/jsx/blob/master/AST.md.
The grammar extension is summarized below (adopted from the specification linked above).
Lexical Grammar
JSXIdentifier :: JSXIdentifierStart | JSXIdentifier JSXIdentifierPart
JSXIdentifierStart :: IdentifierStart (but not
\
)JSXIdentifierPart :: IdentifierPart (but_not
\
) |-
JSXText :: JSXTextCharacter JSXTextopt
JSXTextCharacter :: SourceCharacter but not one of
{
,<
,>
or}
JSXStringLiteral ::
'
JSXText'
|"
JSXText"
Primary expression
JSX extends the PrimaryExpression in the ECMAScript 6th Edition (ECMA-262) grammar:
PrimaryExpression :: JSXElement
Elements
Note: names of JSXOpeningElement and JSXClosingElement should match.
JSXElement :: JSXSelfClosingElement | JSXOpeningElement JSXChildrenopt JSXClosingElement
JSXSelfClosingElement ::
<
JSXElementName JSXAttributesopt/
>
JSXOpeningElement ::
<
JSXElementName JSXAttributesopt>
JSXClosingElement ::
<
/
JSXElementName>
JSXElementName :: JSXIdentifier | JSXNamedspacedName | JSXMemberExpression
JSXNamespacedName :: JSXIdentifier
:
JSXIdentifierJSXMemberExpression :: JSXIdentifier
.
JSXIdentifier | JSXMemberExpression.
JSXIdentifierAttributes
JSXAttributes :: JSXSpreadAttribute JSXAttributesopt | JSXAttribute JSXAttributesopt
JSXSpreadAttribute ::
{
...
AssignmentExpression}
JSXAttribute :: JSXAttributeName | JSXAttributeName
=
JSXAttributeValueJSXAttributeName :: JSXIdentifier | JSXNamespacedName
JSXAttributeValue :: StringLiteral |
{
AssignmentExpression}
| JSXElementChildren
JSXChildren : JSXChild JSXChildrenopt
JSXChild :: JSXText | JSXElement |
{
AssignmentExpressionopt}
The text was updated successfully, but these errors were encountered: