Given an ast of all the lines in a function, create the node along with the calls and variables internal to it. Also make the nested subnodes :param tree ast: :param parent Group: :rtype: list[Node]
(tree, parent)
| 318 | |
| 319 | @staticmethod |
| 320 | def make_nodes(tree, parent): |
| 321 | """ |
| 322 | Given an ast of all the lines in a function, create the node along with the |
| 323 | calls and variables internal to it. |
| 324 | Also make the nested subnodes |
| 325 | |
| 326 | :param tree ast: |
| 327 | :param parent Group: |
| 328 | :rtype: list[Node] |
| 329 | """ |
| 330 | is_constructor = False |
| 331 | if tree.get('kind') == 'constructor': |
| 332 | token = '(constructor)' |
| 333 | is_constructor = True |
| 334 | elif tree['type'] == 'FunctionDeclaration': |
| 335 | token = tree['id']['name'] |
| 336 | elif tree['type'] == 'MethodDefinition': |
| 337 | token = tree['key']['name'] |
| 338 | |
| 339 | if tree['type'] == 'FunctionDeclaration': |
| 340 | full_node_body = tree['body'] |
| 341 | else: |
| 342 | full_node_body = tree['value'] |
| 343 | |
| 344 | subgroup_trees, subnode_trees, this_scope_body = Javascript.separate_namespaces(full_node_body) |
| 345 | if subgroup_trees: |
| 346 | # TODO - this is when a class is defined within a function |
| 347 | # It's unusual but should probably be handled in the future. |
| 348 | # Handling this use case would require some code reorganziation. |
| 349 | # Take a look at class_in_function.js to better understand. |
| 350 | logging.warning("Skipping class defined within a function!") |
| 351 | |
| 352 | line_number = lineno(tree) |
| 353 | calls = make_calls(this_scope_body) |
| 354 | variables = make_local_variables(this_scope_body, parent) |
| 355 | node = Node(token, calls, variables, parent=parent, line_number=line_number, |
| 356 | is_constructor=is_constructor) |
| 357 | subnodes = flatten([Javascript.make_nodes(t, node) for t in subnode_trees]) |
| 358 | |
| 359 | return [node] + subnodes |
| 360 | |
| 361 | @staticmethod |
| 362 | def make_root_node(lines, parent): |
no test coverage detected