Skip to content

Verify scope tree and symbols table match TypeScript #4316

@overlookmotel

Description

@overlookmotel

Recent changes (e.g. #4310) align our scope tree with TypeScript compiler. #3990 added much-needed testing for correctness of the scopes tree by copying all @typescript-eslint/scope-manager's test cases.

However, the approach #3990 takes is to:

  • Copy all the test cases from @typescript-eslint/scope-manager.
  • Run Oxc's semantic analysis on each test case.
  • Snapshot ScopeTree and Symbols.
  • When changes occur, ensure the snapshots don't change.

This will catch any regressions in future PRs (great!) but what we are not testing is whether Oxc's current implementation is correct. We just assume it is. It would be ideal to ensure this assumption is correct.

@typescript-eslint/scope-manager repo also includes snapshots of its scopes tree (example) for all the fixtures we've copied. We could compare Oxc's scopes + symbols info to these snapshots. If our implementation correctly matches TS's, then they should match.

@typescript-eslint/scope-manager's structure for storing scope info is a bit different from Oxc's, so we'd have to translate between the two to compare them. But they are broadly similar, so I don't think this would be too hard.

But... and it is quite a big "but"... the problem is that @typescript-eslint/scope-manager's snapshots are in Jest snapshot format. We would need to have a way to parse them. I can see 2 potential ways to do this:

  1. Run a regex on the Jest snapshots to turn them into valid JSON, which we can then convert to Rust structs with serde.
  2. Write a custom parser for this format (perhaps copying logic from NPM package jest-snapshot-parser if it's any good).

The thing we have on our side is that the format of these snapshots is predictable as they're computer-generated - they should all follow exactly same structure, and there shouldn't be weird edge cases to handle when parsing them. So perhaps the quick-and-dirty regex-to-JSON approach may be viable.

I am guessing (2) should be possible with something like nom, but I've never used nom and don't have any idea how quick it'd be to build. Or maybe implementing Jest snapshots as a Serde format is also an option.

Does anyone who has more experience of this kind of problem offer any advice?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions