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

Align JS-side AST with standard for JSX #9703

Open
overlookmotel opened this issue Mar 12, 2025 · 1 comment
Open

Align JS-side AST with standard for JSX #9703

overlookmotel opened this issue Mar 12, 2025 · 1 comment
Labels
A-ast Area - AST C-enhancement Category - New feature or request E-Help Wanted Experience level - For the experienced collaborators

Comments

@overlookmotel
Copy link
Contributor

Our AST on JS side (via oxc-parser NPM package) is now aligned with ESTree standard.

We have conformance tests which ensure our AST is exactly the same as Acorn's AST for all Test262 test cases which Acorn can parse.

Aim

We should ensure our JS-side AST is aligned to a common standard for JSX too.

The JSX spec only specifies JSX grammar, but not field names etc for an AST that includes JSX nodes. acorn-jsx appears to be popular (40m weekly NPM downloads), so I suggest it's a good target to align with.

The extensions to AST for JSX are quite minimal (only a handful of types), so it's possible that our AST is already perfectly aligned. But we should adopt a conformance test suite which is run in CI so we can (a) ensure that's correct and (b) make sure we don't break it accidentally in future.

Suggested plan

I suggest that we:

Use the test cases from acorn-jsx as our target for conformance. The JSON snapshots in that file are not great, because they include loc and range properties. But we could:

  • Use the inputs from those tests.
  • Parse them all with Acorn using acorn-jsx plugin.
  • Record that output as JSON files.

Use same methodology as for the ESTree conformance tests:

@overlookmotel
Copy link
Contributor Author

overlookmotel commented Mar 14, 2025

Conformance test suite (based on acorn-jsx) has been implemented in #9745 and #9769 (thanks @hi-ogawa!). Various other PRs have corrected AST shape for JSX nodes.

JS-side AST is now acorn-jsx-compatible, with one exception: we need to decode HTML entities in JSXText in parser (#9667).

3 negative conformance tests are also failing, but those relate to oxc_parser not being as strict as Acorn. They're not problems with conversion of AST to ESTree (#9769 (comment)).


If we wanted to increase our test coverage, Babel has a ton of test cases for JSX too: https://github.com/babel/babel/tree/33110bf6a6e47ee084a79050a20ea67d9317af20/packages/babel-parser/test/fixtures/jsx

@Boshen Boshen added the E-Help Wanted Experience level - For the experienced collaborators label Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ast Area - AST C-enhancement Category - New feature or request E-Help Wanted Experience level - For the experienced collaborators
Projects
None yet
Development

No branches or pull requests

2 participants