Skip to content

esprima throws on React Fragment shorthand notation #1337

Open
@Jazzmanpw

Description

@Jazzmanpw

Steps to reproduce

import {parse} from 'recast'

parse('<></>')

Expected result

A Program is returned with JSXFragmen expression

Actual result

An error is thrown

Error: Line 1: Unexpected token >
    at ErrorHandler.constructError (...\node_modules\esprima\dist\esprima.js:5012:22)
    at ErrorHandler.createError (...\node_modules\esprima\dist\esprima.js:5028:27)
    at JSXParser.Parser.unexpectedTokenError (...\node_modules\esprima\dist\esprima.js:1985:39)
    at JSXParser.Parser.throwUnexpectedToken (...\node_modules\esprima\dist\esprima.js:1995:21)
    at JSXParser.parseJSXIdentifie ( ...\node_modules\esprima\dist\esprima.js:724:19)
    at JSXParser.parseJSXElementName (...\node_modules\esprima\dist\esprima.js:730:33)
    at JSXParser.parseJSXOpeningElement (...\node_modules\esprima\dist\esprima.js:817:26)
    at JSXParser.parseJSXElement (...\node_modules\esprima\dist\esprima.js:926:29)
    at JSXParser.parseJSXRoot (...\node_modules\esprima\dist\esprima.js:942:29)
    at JSXParser.parsePrimaryExpression (...\node_modules\esprima\dist\esprima.js:466:40)

I found an issue from esprima, but it was fixed long ago. Also I found a recast issue, but it had different error and provided no details on solution

Current workaround that I found is to pass babel parser, but esprima can handle this case, so I'm confused why it's happening

import * as babelParser from 'recast/parsers/babel';

parse('<></>', {parser: babelParser}); // parses with no issues

Any idea on why is it happening?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions