MCPcopy Create free account
hub / github.com/scottrogowski/code2flow / make_local_variables

Function make_local_variables

code2flow/javascript.py:174–200  ·  view source on GitHub ↗

Given an ast of all the lines in a function, generate a list of variables in that function. Variables are tokens and what they link to. In this case, what it links to is just a string. However, that is resolved later. Also return variables for the outer scope parent :param

(tree, parent)

Source from the content-addressed store, hash-verified

172
173
174def make_local_variables(tree, parent):
175 """
176 Given an ast of all the lines in a function, generate a list of
177 variables in that function. Variables are tokens and what they link to.
178 In this case, what it links to is just a string. However, that is resolved
179 later.
180
181 Also return variables for the outer scope parent
182
183 :param tree list|dict:
184 :param parent Group:
185 :rtype: list[Variable]
186 """
187 if not tree:
188 return []
189
190 variables = []
191 for element in walk(tree):
192 if element['type'] == 'VariableDeclaration':
193 variables += process_assign(element)
194
195 # Make a 'this' variable for use anywhere we need it that points to the class
196 if isinstance(parent, Group) and parent.group_type == GROUP_TYPE.CLASS:
197 variables.append(Variable('this', parent, lineno(tree)))
198
199 variables = list(filter(None, variables))
200 return variables
201
202
203def children(tree):

Callers 2

make_nodesMethod · 0.70
make_root_nodeMethod · 0.70

Calls 4

VariableClass · 0.85
walkFunction · 0.70
process_assignFunction · 0.70
linenoFunction · 0.70

Tested by

no test coverage detected