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

estree: acorn and typescript eslint ast conformance suite #8630

Open
Boshen opened this issue Jan 21, 2025 · 3 comments
Open

estree: acorn and typescript eslint ast conformance suite #8630

Boshen opened this issue Jan 21, 2025 · 3 comments
Assignees
Labels
A-ast Area - AST
Milestone

Comments

@Boshen
Copy link
Member

Boshen commented Jan 21, 2025

#2854 (comment)

@Boshen Boshen added the A-ast Area - AST label Jan 21, 2025
@Boshen Boshen added this to the estree milestone Jan 21, 2025
@Boshen Boshen self-assigned this Jan 21, 2025
@overlookmotel
Copy link
Contributor

Copying the referenced comment from #2854 for ease:

To surface all the obscure differences between our JS-side AST and ESTree, I think we ideally need conformance tests. Initially we'll have tons of failures, but we can chip away at them until there are none. I suggest:

  • Parse all Test262 fixtures with Acorn and write the resulting ASTs as JSON files.
  • Run Oxc parser on same fixtures and serialize to JSON with serde.
  • Conformance runner compare the two, and generate snapshot files showing which fixtures fail.

The Acorn AST JSON files will take time to compute and will be many many files. We could:

  • Create a new repo with the code to run Acorn.
  • Check in the resulting JSON files to that repo.
  • Link that repo into main Oxc repo as a git submodule (same as we do with Test262, Babel, etc fixtures).

Then the conformance tests could be written purely in Rust, and we only need to run Acorn once, not every time conformance runs.

That'll only cover us for JS syntax. I guess we could do similar for TS ASTs using fixtures from TypeScript repo and using typescript-eslint's parser to generate the JSON files. But personally I think we should concentrate on the JS AST first.

Does that sound like a good idea? If so, does anyone have an interest in building the infrastructure?

@Boshen
Copy link
Member Author

Boshen commented Jan 22, 2025

  • take a look at what rollup parseAST conforms to

According to https://github.com/rollup/rollup/pull/5073:

As a by-product of the process, the custom swc AST is converted to an ESTree-compliant AST, which has been verified by deep comparison with the acorn AST for all Rollup test cases.

.d.ts:

https://www.npmjs.com/package/rollup

import type * as estree from 'estree';

export type ParseAst = (
	input: string,
	options?: { allowReturnOutsideFunction?: boolean; jsx?: boolean }
) => ProgramNode;

type ProgramNode = RollupAstNode<estree.Program>;

@Boshen
Copy link
Member Author

Boshen commented Jan 23, 2025

I revived https://github.com/oxc-project/acorn-test262 and wrote a quick runner in https://github.com/oxc-project/oxc/compare/estree, nothing matches right now due to ts syntaxes.

   "body": [
     {
       "declarations": [
         {
+          "definite": false,
           "end": 255,
           "id": {
             "end": 227,
             "name": "result",
+            "optional": false,
             "start": 221,
-            "type": "Identifier"
+            "type": "Identifier",
+            "typeAnnotation": null
           },
           "init": {
             "arguments": [
               {
                 "end": 250,
+                "raw": "null",

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

No branches or pull requests

2 participants