@@ -22,44 +22,43 @@ 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 ] = (
39+ self .current_scope_id
40+ )
4241 elif (
4342 child .parent .type == "arrow_function"
4443 or child .parent .type == "function_expression"
4544 ):
4645 if child .parent .parent :
4746 self .function_root_to_scope_id [child .parent .parent ] = (
48- scope_id
47+ self . current_scope_id
4948 )
5049
51- scope_id += 1
50+ self . current_scope_id += 1
5251 search (child )
5352 scope_stack .pop ()
5453 else :
5554 search (child )
5655
5756 return
5857
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
58+ self .scope_env [self . current_scope_id ] = (tree .root_node , set ())
59+ self .scope_root_to_scope_id [tree .root_node ] = self . current_scope_id
60+ scope_stack .append (self . current_scope_id )
61+ self . current_scope_id += 1
6362 search (tree .root_node )
6463 return
6564
0 commit comments