Skip to content

Support JSX Syntax #1467

@ariya

Description

@ariya

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 }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions