Skip to content

Commit 0c03d02

Browse files
committed
Preventd overwriting of scope_env when parsing multiple files
1 parent 2388b59 commit 0c03d02

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

src/tstool/analyzer/Javascript_TS_analyzer.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,41 @@ def extract_scope_info(self, tree: tree_sitter.Tree) -> None:
2222
:param tree: Parsed syntax tree
2323
"""
2424
scope_stack: List[int] = []
25-
scope_id: int = 0
2625

2726
def search(root: Node) -> None:
28-
nonlocal scope_id
29-
3027
for child in root.children:
3128
if child.type == "statement_block":
3229
if len(scope_stack) > 0:
33-
self.scope_env[scope_stack[-1]][1].add(scope_id)
30+
self.scope_env[scope_stack[-1]][1].add(self.current_scope_id)
3431

35-
self.scope_env[scope_id] = (child, set())
36-
self.scope_root_to_scope_id[child] = scope_id
37-
scope_stack.append(scope_id)
32+
self.scope_env[self.current_scope_id] = (child, set())
33+
self.scope_root_to_scope_id[child] = self.current_scope_id
34+
scope_stack.append(self.current_scope_id)
3835

3936
if child.parent:
4037
if child.parent.type == "function_declaration":
41-
self.function_root_to_scope_id[child.parent] = scope_id
38+
self.function_root_to_scope_id[child.parent] = self.current_scope_id
4239
elif (
4340
child.parent.type == "arrow_function"
4441
or child.parent.type == "function_expression"
4542
):
4643
if child.parent.parent:
4744
self.function_root_to_scope_id[child.parent.parent] = (
48-
scope_id
45+
self.current_scope_id
4946
)
5047

51-
scope_id += 1
48+
self.current_scope_id += 1
5249
search(child)
5350
scope_stack.pop()
5451
else:
5552
search(child)
5653

5754
return
5855

59-
self.scope_env[scope_id] = (tree.root_node, set())
60-
self.scope_root_to_scope_id[tree.root_node] = scope_id
61-
scope_stack.append(scope_id)
62-
scope_id += 1
56+
self.scope_env[self.current_scope_id] = (tree.root_node, set())
57+
self.scope_root_to_scope_id[tree.root_node] = self.current_scope_id
58+
scope_stack.append(self.current_scope_id)
59+
self.current_scope_id += 1
6360
search(tree.root_node)
6461
return
6562

src/tstool/analyzer/TS_analyzer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def __init__(
177177
self.globals_env: Dict[int, Value] = {}
178178
self.scope_env: Dict[int, Tuple[Node, Set[int]]] = {}
179179
self.api_env: Dict[int, API] = {}
180+
181+
self.current_scope_id: int = 0
180182

181183
# Dictionary storing mapping from the root node of the scope to its scope id
182184
self.scope_root_to_scope_id: Dict[Node, int] = {}

0 commit comments

Comments
 (0)