From bcb33c00fa574f65ccc8cf6ee990b618cae75c3b Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:47:27 +0000 Subject: [PATCH] test(semantic): add a test for catch parameters reference (#7988) I am trying to clean up Semantic, just found that we can remove this code without any test failing, but it should fail in that test case I added. https://github.com/oxc-project/oxc/blob/1082868855ba67b03a5bd03211f1b23262976410/crates/oxc_semantic/src/builder.rs#L2085-L2087 --- .../fixtures/oxc/js/try-catch/parameters.js | 9 ++ .../fixtures/oxc/js/try-catch/parameters.snap | 87 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 crates/oxc_semantic/tests/fixtures/oxc/js/try-catch/parameters.js create mode 100644 crates/oxc_semantic/tests/fixtures/oxc/js/try-catch/parameters.snap diff --git a/crates/oxc_semantic/tests/fixtures/oxc/js/try-catch/parameters.js b/crates/oxc_semantic/tests/fixtures/oxc/js/try-catch/parameters.js new file mode 100644 index 0000000000000..53ff90329e136 --- /dev/null +++ b/crates/oxc_semantic/tests/fixtures/oxc/js/try-catch/parameters.js @@ -0,0 +1,9 @@ +let a = 0, A = 0; +try { } catch ( + { a = A, +// ^ is referenced to parent scope's `A` + b = a } +// ^ is referenced to parameter `a` +) { + let A = 0 ; +} diff --git a/crates/oxc_semantic/tests/fixtures/oxc/js/try-catch/parameters.snap b/crates/oxc_semantic/tests/fixtures/oxc/js/try-catch/parameters.snap new file mode 100644 index 0000000000000..a71051d30f73d --- /dev/null +++ b/crates/oxc_semantic/tests/fixtures/oxc/js/try-catch/parameters.snap @@ -0,0 +1,87 @@ +--- +source: crates/oxc_semantic/tests/main.rs +input_file: crates/oxc_semantic/tests/fixtures/oxc/js/try-catch/parameters.js +--- +[ + { + "children": [ + { + "children": [], + "flags": "ScopeFlags(StrictMode)", + "id": 1, + "node": "BlockStatement", + "symbols": [] + }, + { + "children": [ + { + "children": [], + "flags": "ScopeFlags(StrictMode)", + "id": 3, + "node": "BlockStatement", + "symbols": [ + { + "flags": "SymbolFlags(BlockScopedVariable | CatchVariable)", + "id": 2, + "name": "a", + "node": "CatchParameter", + "references": [ + { + "flags": "ReferenceFlags(Read)", + "id": 1, + "name": "a", + "node_id": 22 + } + ] + }, + { + "flags": "SymbolFlags(BlockScopedVariable | CatchVariable)", + "id": 3, + "name": "b", + "node": "CatchParameter", + "references": [] + }, + { + "flags": "SymbolFlags(BlockScopedVariable)", + "id": 4, + "name": "A", + "node": "VariableDeclarator(A)", + "references": [] + } + ] + } + ], + "flags": "ScopeFlags(StrictMode | CatchClause)", + "id": 2, + "node": "CatchClause", + "symbols": [] + } + ], + "flags": "ScopeFlags(StrictMode | Top)", + "id": 0, + "node": "Program", + "symbols": [ + { + "flags": "SymbolFlags(BlockScopedVariable)", + "id": 0, + "name": "a", + "node": "VariableDeclarator(a)", + "references": [] + }, + { + "flags": "SymbolFlags(BlockScopedVariable)", + "id": 1, + "name": "A", + "node": "VariableDeclarator(A)", + "references": [ + { + "flags": "ReferenceFlags(Read)", + "id": 0, + "name": "A", + "node_id": 17 + } + ] + } + ] + } +]