-
-
Notifications
You must be signed in to change notification settings - Fork 722
Description
Our AST on JS side (via oxc-parser NPM package) is now aligned with ESTree standard for JS syntax. 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.
However, we do not yet guarantee that our AST for TypeScript types is aligned with any particular standard.
TS-ESLint's parser seems like the obvious target.
Achieving alignment
Recently there have been various PRs to align parts of the AST with TS-ESLint.
In my opinion, it'd be preferable if we took a more systematic approach, using a conformance suite. This will ensure:
- We don't miss anything, and can confidently assert our complete alignment with TS-ESLint.
- We don't break anything in future.
- While making changes to align one type, we don't inadvertently break another.
This methodology proved successful while working on ESTree comatibility. Once we had the conformance suite working, we got to 99% passing within a few days!
I suggest we adopt same approach as I've outlined in #9703, with the target snapshots generated in and committed to acorn-test262 repo. We can:
- Use all the test cases in https://github.com/microsoft/TypeScript/tree/main/tests/cases/conformance and https://github.com/microsoft/TypeScript/tree/main/tests/cases/compiler.
- Parse all these cases with TS-ESLint parser, convert the resulting ASTs to JSON, and commit those JSON files to the repo.
How
Wherever possible, it's preferable to use the DSL (domain specific language) provided by #[estree] attributes on AST types to control how the AST gets converted e.g. #[estree(flatten)], #[estree(rename = "...")], #[estree(append_to = "...")].
We can also use custom converters #[estree(via = ...)] where necessary, but the less we have to resort to that, the better.
Conflicts between ESTree and TS-ESLint
It's possible that we'll run into cases where Acorn and TS-ESLint produce a different AST for some JS syntax. If so, that'll be problematic. Ideally we want a single AST shape which is compatible with both ESTree and TS-ESLint.
If we do find such cases, I suggest that we just skip them initially. Once we have everything else passing, we can see how broad a problem this is, and figure out how best to deal with it.
Raw transfer
I suggest that in the inital alignment effort, we don't worry about raw transfer.
Let's only adapt the AST that Oxc generates as JSON via ESTree trait. This will be simpler to do, and will get us to the finish line faster.
Only once we have all the tests passing, we can then work on getting the AST generated by raw transfer aligned too. This is generally much easier once you have a working ESTree impl to translate from.
JSX
See #9703. I suggest we do JSX first before TS.