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

Method separate_namespaces

code2flow/javascript.py:289–317  ·  view source on GitHub ↗

Given an AST, recursively separate that AST into lists of ASTs for the subgroups, nodes, and body. This is an intermediate step to allow for cleaner processing downstream :param tree ast: :returns: tuple of group, node, and body trees. These are processed

(tree)

Source from the content-addressed store, hash-verified

287
288 @staticmethod
289 def separate_namespaces(tree):
290 """
291 Given an AST, recursively separate that AST into lists of ASTs for the
292 subgroups, nodes, and body. This is an intermediate step to allow for
293 cleaner processing downstream
294
295 :param tree ast:
296 :returns: tuple of group, node, and body trees. These are processed
297 downstream into real Groups and Nodes.
298 :rtype: (list[ast], list[ast], list[ast])
299 """
300
301 groups = []
302 nodes = []
303 body = []
304 for el in children(tree):
305 if el['type'] in ('MethodDefinition', 'FunctionDeclaration'):
306 nodes.append(el)
307 elif el['type'] == 'ClassDeclaration':
308 groups.append(el)
309 else:
310 tup = Javascript.separate_namespaces(el)
311 if tup[0] or tup[1]:
312 groups += tup[0]
313 nodes += tup[1]
314 body += tup[2]
315 else:
316 body.append(el)
317 return groups, nodes, body
318
319 @staticmethod
320 def make_nodes(tree, parent):

Callers 2

make_nodesMethod · 0.45
make_class_groupMethod · 0.45

Calls 1

childrenFunction · 0.70

Tested by

no test coverage detected