-
Notifications
You must be signed in to change notification settings - Fork 775
Support JSX Syntax #1467
Description
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 : JSXIdentifier
JSXMemberExpression :: JSXIdentifier . JSXIdentifier | JSXMemberExpression . JSXIdentifier
Attributes
JSXAttributes :: JSXSpreadAttribute JSXAttributesopt | JSXAttribute JSXAttributesopt
JSXSpreadAttribute :: { ... AssignmentExpression }
JSXAttribute :: JSXAttributeName | JSXAttributeName = JSXAttributeValue
JSXAttributeName :: JSXIdentifier | JSXNamespacedName
JSXAttributeValue :: StringLiteral | { AssignmentExpression } | JSXElement
Children
JSXChildren : JSXChild JSXChildrenopt
JSXChild :: JSXText | JSXElement | { AssignmentExpressionopt }