Skip to content
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

esprima throws on React Fragment shorthand notation #1337

Open
Jazzmanpw opened this issue Jul 5, 2023 · 1 comment
Open

esprima throws on React Fragment shorthand notation #1337

Jazzmanpw opened this issue Jul 5, 2023 · 1 comment

Comments

@Jazzmanpw
Copy link

Jazzmanpw commented Jul 5, 2023

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?

@eventualbuddha
Copy link
Collaborator

Looks like jquery/esprima#2020 isn't actually fixed, so that's likely the cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants