@@ -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
0 commit comments