oxc/crates
DonIsaac 93575cd09e test(semantic): add comprehensive regression test suite (#5976)
# What This PR Does

Enhance's `oxc_semantic`'s integration tests with a regression test suite that ensures semantic's contract guarantees hold over all test cases in typescript-eslint's scope snapshot tests. Each test case checks a separate assumption and runs independently from other test cases.

This PR sets up the code infrastructure for this test suite and adds two test cases to start us off:
1. Reflexivity tests for `IdentifierReference` and `Reference`
2. Symbol declaration reflexivity tests between declarations in `SymbolTable` and their corresponding node in the AST.

Please refer to the doc comments for each of these tests for an in-depth explanation.

## Aren't our existing tests sufficient?
`oxc_semantic` is currently tested directly via
1. scope snapshot tests, ported from `typescript-eslint`
2. Hand-written tests using `SemanticTester` in `tests/integration`

And indirectly via

3. Conformance test suite over Test262/TypeScript/Babel
4. Linter snapshot tests

Shouldn't this be sufficient? I argue not, for two reasons:

## 1. Clarify Contract Ambiguity

When using `Semantic`, I often find myself asking these questions?
* Does `semantic.symbols().get_declaration(id)` point to a `BindingIdentifer`/`BindingPattern` or the declaration that holds an identifier/pattern?
* Will a `Reference`'s `node_id` point me to an `IdentifierReference` or the expression/statement that is holding an `IdentifierReference`?
* When will `BindingIdentifier`'s `symbol_id` get populated? can we guarantee that after semantic analysis it will never be `None`?
* What actually _is_ the node covered by `semantic.symbols().get_span(id)`? This one really messed me up, and resulted in me creating #4739.
* What scope does `Function::scope_id` point to? The one where the function is declared? The one created by its body? The one created by the type annotations but before the function body? Or something else entirely?

**These test cases are meant to answer such questions and guarnatee those answers as test cases**. No other existing testing solution currently upholds such promises: they only tell us if code expecting one answer or another produces an unexpected result. However, those parts of the codebase could always be adjusted to conform to new `Semantic` behavior, meaning no contract guarantees are actually upheld.

## 2. Existing Tests Do Not Test The Same Behavior

I'll cover each above listed test case one-by-one:

1. For starters, these tests only cover scopes. Additionally, they only tell us **how behavior has changed**, not that **behavior is now incorrect**.
2. These _do_ generally cover the same behaviors, but **are not comprehensive and are difficult to maintain**. These are unit tests that should be used hand-in-hand with this new test suite.
3. The most relevant tests here are for the parser. However, these tests **only tell us if a syntax/parse error was produced**, and tell us nothing about the validity of `Semantic`.
4. Relying on lint rule's output is a a mediiocre proxy of `Semantic`'s behavior at best. They can tell us if changes to `Semantic` break assumptions made by lint rules, but they do not tell us if **those assumptions are the ones we want to uphold to external crates consuming `Semantic`.
2024-09-25 02:24:57 +00:00
..
oxc docs(oxc): add README.md and crate-level docs (#6035) 2024-09-25 02:16:31 +00:00
oxc_allocator docs(allocator): document oxc_allocator crate (#6037) 2024-09-25 02:16:32 +00:00
oxc_ast feat(transformer): do not transform ** with bigint literals (#6023) 2024-09-24 10:33:02 +00:00
oxc_ast_macros release(crates): v0.30.1 (#6016) 2024-09-24 14:03:03 +08:00
oxc_cfg release(crates): v0.30.1 (#6016) 2024-09-24 14:03:03 +08:00
oxc_codegen fix(semantic,codegen,transformer): handle definite ! operator in variable declarator (#6019) 2024-09-24 08:32:05 +00:00
oxc_diagnostics fix(diagnostics): check for terminal when displaying links (#6018) 2024-09-24 07:18:07 +00:00
oxc_index release(crates): v0.30.1 (#6016) 2024-09-24 14:03:03 +08:00
oxc_isolated_declarations fix(semantic,codegen,transformer): handle definite ! operator in variable declarator (#6019) 2024-09-24 08:32:05 +00:00
oxc_language_server chore(oxc): ban std::collections::HashMap in favor of FxHashMap (#5996) 2024-09-24 16:41:36 +08:00
oxc_linter fix(linter): no-useless-escape: do not crash on backslash character (#6048) 2024-09-24 23:25:49 +00:00
oxc_macros feat(linter): add oxc-security/api-keys (#5906) 2024-09-22 22:39:56 +00:00
oxc_mangler release(crates): v0.30.1 (#6016) 2024-09-24 14:03:03 +08:00
oxc_minifier fix(minifier): compute void number as undefined (#6028) 2024-09-24 14:39:44 +00:00
oxc_module_lexer release(crates): v0.30.1 (#6016) 2024-09-24 14:03:03 +08:00
oxc_parser fix(paresr): do not report missing initializer error in ambient context (#6020) 2024-09-24 09:04:09 +00:00
oxc_prettier refactor(ast): move all ts ast related impl methods to ast_impl (#6015) 2024-09-24 06:07:37 +00:00
oxc_regular_expression release(crates): v0.30.1 (#6016) 2024-09-24 14:03:03 +08:00
oxc_semantic test(semantic): add comprehensive regression test suite (#5976) 2024-09-25 02:24:57 +00:00
oxc_sourcemap release(crates): v0.30.1 (#6016) 2024-09-24 14:03:03 +08:00
oxc_span release(crates): v0.30.1 (#6016) 2024-09-24 14:03:03 +08:00
oxc_syntax fix(minifier): compute void number as undefined (#6028) 2024-09-24 14:39:44 +00:00
oxc_transformer feat(transformer): do not transform ** with bigint literals (#6023) 2024-09-24 10:33:02 +00:00
oxc_traverse release(crates): v0.30.1 (#6016) 2024-09-24 14:03:03 +08:00
oxc_wasm feat(oxc_wasm): add verbse option to debug_dot (#5879) 2024-09-19 06:13:03 +00:00