-
-
Notifications
You must be signed in to change notification settings - Fork 932
Description
oxc/crates/oxc_semantic/tests/util/mod.rs
Lines 15 to 19 in 9aa78f6
| pub struct SemanticTester { | |
| allocator: Allocator, | |
| source_type: SourceType, | |
| source_text: &'static str, | |
| } |
The current SemanticTester is great to do many kinds of assertions. Such as
oxc/crates/oxc_semantic/tests/symbols.rs
Lines 8 to 13 in 9aa78f6
| SemanticTester::js("export class Foo {}") | |
| .has_root_symbol("Foo") | |
| .contains_flags(SymbolFlags::Class | SymbolFlags::Export) | |
| .has_number_of_references(0) | |
| .is_exported() | |
| .test(); |
But I kind of think the SemanticTester might not be that intuitive for testing general scope resolving logic, which means weather the symbol has correct scope and don't care about the flags or others.
Let's see we have test case
log()
let a = 1
log(a)
let b = 1
log(b)
{
let a = 2
log(a)
log(b)
}we could transform it to
log#0()
let a#1 = 1
log(a#1)
let b#1 = 1;
log(b#1);
{
let a#2 = 2;
log(a#2)
log(b#1)
}the x in #x is the ScopeId we get from the Sematics.
In this way, we could easily visualize the whether the scope is correct. And with snapshot testing, this could be a general way for testing without any other kinds of assertions.
I get this idea from contributing to swc. https://github.com/swc-project/swc/blob/main/crates/swc_ecma_transforms_base/tests/resolver/hoisting/output.js
Metadata
Metadata
Assignees
Labels
Type
Fields
Give feedbackPriority