test(semantic): add JSXIdentifierReference-related tests (#5224)

These tests demonstrate what kind of JSX will have references.
This commit is contained in:
Dunqing 2024-08-30 17:43:34 +00:00
parent 7e2a7afaa4
commit be7b8c6845
5 changed files with 82 additions and 1 deletions

View file

@ -0,0 +1,2 @@
let Component = () => <div></div>;
<Component></Component>

View file

@ -0,0 +1,42 @@
---
source: crates/oxc_semantic/tests/main.rs
input_file: crates/oxc_semantic/tests/fixtures/oxc/jsx/element-name.jsx
---
[
{
"children": [
{
"children": [],
"flags": "ScopeFlags(StrictMode | Function | Arrow)",
"id": 1,
"node": "ArrowFunctionExpression",
"symbols": []
}
],
"flags": "ScopeFlags(StrictMode | Top)",
"id": 0,
"node": "Program",
"symbols": [
{
"flags": "SymbolFlags(BlockScopedVariable | ArrowFunction)",
"id": 0,
"name": "Component",
"node": "VariableDeclarator(Component)",
"references": [
{
"flags": "ReferenceFlags(Read)",
"id": 0,
"name": "Component",
"node_id": 19
},
{
"flags": "ReferenceFlags(Read)",
"id": 1,
"name": "Component",
"node_id": 22
}
]
}
]
}
]

View file

@ -0,0 +1,3 @@
let A = {};
<A.B.C></A.B.C>;

View file

@ -0,0 +1,34 @@
---
source: crates/oxc_semantic/tests/main.rs
input_file: crates/oxc_semantic/tests/fixtures/oxc/jsx/member-expression.jsx
---
[
{
"children": [],
"flags": "ScopeFlags(StrictMode | Top)",
"id": 0,
"node": "Program",
"symbols": [
{
"flags": "SymbolFlags(BlockScopedVariable)",
"id": 0,
"name": "A",
"node": "VariableDeclarator(A)",
"references": [
{
"flags": "ReferenceFlags(Read)",
"id": 0,
"name": "A",
"node_id": 13
},
{
"flags": "ReferenceFlags(Read)",
"id": 1,
"name": "A",
"node_id": 22
}
]
}
]
}
]

View file

@ -111,7 +111,7 @@ fn analyze(path: &Path, source_text: &str) -> String {
/// cargo test --package oxc_semantic --test main
#[test]
fn main() {
insta::glob!("fixtures/**/*.{ts,tsx}", |path| {
insta::glob!("fixtures/**/*.{js,jsx,ts,tsx}", |path| {
let source_text = fs::read_to_string(path).unwrap();
let snapshot = analyze(path, &source_text);
let name = path.file_stem().unwrap().to_str().unwrap();