Skip to content

Commit

Permalink
test(semantic): add JSXIdentifierReference-related tests (#5224)
Browse files Browse the repository at this point in the history
These tests demonstrate what kind of JSX will have references.
  • Loading branch information
Dunqing committed Aug 30, 2024
1 parent 7e2a7af commit be7b8c6
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crates/oxc_semantic/tests/fixtures/oxc/jsx/element-name.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let Component = () => <div></div>;
<Component></Component>
42 changes: 42 additions & 0 deletions crates/oxc_semantic/tests/fixtures/oxc/jsx/element-name.snap
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let A = {};

<A.B.C></A.B.C>;
34 changes: 34 additions & 0 deletions crates/oxc_semantic/tests/fixtures/oxc/jsx/member-expression.snap
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
}
]
2 changes: 1 addition & 1 deletion crates/oxc_semantic/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit be7b8c6

Please sign in to comment.