MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeText-parser / JavascriptParser

Class JavascriptParser

src/codetext/parser/javascript_parser.py:10–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class JavascriptParser(LanguageParser):
11
12 FILTER_PATHS = ('test', 'node_modules')
13
14 BLACKLISTED_FUNCTION_NAMES = ['toString', 'toLocaleString', 'valueOf', 'constructor']
15
16 @staticmethod
17 def get_docstring_node(node):
18 docstring_node = []
19 prev_node = node.prev_sibling
20 parent_node = node.parent
21
22 if prev_node and prev_node.type == 'comment':
23 docstring_node.append(prev_node)
24
25 elif parent_node:
26 if parent_node.type != 'class_body': # node not inside a class
27 prev_node = parent_node.prev_sibling
28 if prev_node and prev_node.type == 'comment':
29 docstring_node.append(prev_node)
30
31 return docstring_node
32
33 @staticmethod
34 def get_docstring(node, blob=None):
35 if blob:
36 logger.info('From version `0.0.6` this function will update argument in the API')
37 docstring_node = JavascriptParser.get_docstring_node(node)
38
39 docstring = ''
40 if docstring_node:
41 docstring = get_node_text(docstring_node[0])
42 return docstring
43
44 @staticmethod
45 def get_comment_node(function_node):
46 comment_node = get_node_by_kind(function_node, kind=['comment'])
47 return comment_node
48
49 @staticmethod
50 def get_function_list(node):
51 function_types = ['function_declaration',
52 'function',
53 'method_definition',
54 'generator_function_declaration',
55 'arrow_function',
56 'generator_function']
57 res = get_node_by_kind(node, function_types)
58 for node in res[:]:
59 if not node.children:
60 res.remove(node)
61
62 return res
63
64 @staticmethod
65 def get_class_list(node):
66 res = get_node_by_kind(node, ['class_declaration', 'class'])
67 for node in res[:]:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected