From 27681683cf291df17ef75f09aef193ff249a16ed Mon Sep 17 00:00:00 2001 From: Lexxxzy Date: Fri, 5 Sep 2025 21:19:18 +0300 Subject: [PATCH] fix(js): Proper scope propagation for empty switch statements --- .../src/stack-graphs.tsg | 8 ++++++-- .../test/statements/switch_statement.js | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/languages/tree-sitter-stack-graphs-javascript/src/stack-graphs.tsg b/languages/tree-sitter-stack-graphs-javascript/src/stack-graphs.tsg index 7ca4eee88..ab1d99975 100644 --- a/languages/tree-sitter-stack-graphs-javascript/src/stack-graphs.tsg +++ b/languages/tree-sitter-stack-graphs-javascript/src/stack-graphs.tsg @@ -1863,9 +1863,13 @@ inherit .containing_class_value node @switch_case.before_scope } -(switch_case (_)* @stmts)@switch_case { +(switch_case + value:(_)@value + (_)* @stmts)@switch_case { if (is-empty @stmts) { - edge @switch_case.after_scope -> @switch_case.before_scope + ; scopes flow into the value and then directly out of the case + edge @value.before_scope -> @switch_case.before_scope + edge @switch_case.after_scope -> @value.after_scope } } diff --git a/languages/tree-sitter-stack-graphs-javascript/test/statements/switch_statement.js b/languages/tree-sitter-stack-graphs-javascript/test/statements/switch_statement.js index a40f7f2e9..6c1dd4871 100644 --- a/languages/tree-sitter-stack-graphs-javascript/test/statements/switch_statement.js +++ b/languages/tree-sitter-stack-graphs-javascript/test/statements/switch_statement.js @@ -8,6 +8,11 @@ switch (x) { /**/ x; // ^ defined: 1 y = 2; + case 1: + case 2: + /**/ x; + // ^ defined: 1 + y = 2; default: /**/ x; // ^ defined: 1 @@ -17,7 +22,7 @@ switch (x) { // Flow out /**/ y; -// ^ defined: 10, 14 +// ^ defined: 10, 15, 19 // Flow around