@@ -66,7 +66,10 @@ def resolve_owner(callee):
6666 return OWNER_CONST .UNKNOWN_VAR
6767
6868 if callee ['object' ]['type' ] == 'NewExpression' :
69- return callee ['object' ]['callee' ]['name' ]
69+ if 'name' in callee ['object' ]['callee' ]:
70+ return callee ['object' ]['callee' ]['name' ]
71+ return djoin (callee ['object' ]['callee' ]['object' ]['name' ],
72+ callee ['object' ]['callee' ]['property' ]['name' ])
7073
7174 return OWNER_CONST .UNKNOWN_VAR
7275
@@ -209,7 +212,7 @@ def children(tree):
209212 if type (v ) == dict and v .get ('type' ):
210213 ret .append (v )
211214 if type (v ) == list :
212- ret += v
215+ ret += filter ( None , v )
213216 return ret
214217
215218
@@ -231,7 +234,8 @@ def get_acorn_version():
231234 Get the version of installed acorn
232235 :rtype: str
233236 """
234- return subprocess .check_output (['node' , '-p' , 'require(\' acorn/package.json\' ).version' ])
237+ outp = subprocess .check_output (['node' , '-p' , 'require(\' acorn/package.json\' ).version' ])
238+ return outp .decode ().strip ()
235239
236240
237241class Javascript (BaseLanguage ):
@@ -241,11 +245,12 @@ def assert_dependencies():
241245 assert is_installed ('acorn' ), "Acorn is required to parse javascript files " \
242246 "but was not found on the path. Install it " \
243247 "from npm and try again."
244-
245- if not get_acorn_version () .startswith (b '8.' ):
248+ version = get_acorn_version ()
249+ if not version .startswith ('8.' ):
246250 logging .warning ("Acorn is required to parse javascript files. "
247251 "Version %r was found but code2flow has only been "
248- "tested on 8.*" , get_acorn_version ())
252+ "tested on 8.*" , version )
253+ logging .info ("Using Acorn %s" % version )
249254
250255 @staticmethod
251256 def get_tree (filename , lang_params ):
@@ -266,7 +271,8 @@ def get_tree(filename, lang_params):
266271 "Acorn could not parse file %r. You may have a JS syntax error or "
267272 "if this is an es6-style source, you may need to run code2flow "
268273 "with --source-type=module. "
269- "For more detail, try running the command `acorn %s`. "
274+ "For more detail, try running the command "
275+ "\n acorn %s\n "
270276 "Warning: Acorn CANNOT parse all javascript files. See their docs. " %
271277 (filename , filename )) from None
272278 tree = json .loads (output )
@@ -331,7 +337,12 @@ def make_nodes(tree, parent):
331337 full_node_body = tree ['value' ]
332338
333339 subgroup_trees , subnode_trees , this_scope_body = Javascript .separate_namespaces (full_node_body )
334- assert not subgroup_trees
340+ if subgroup_trees :
341+ # TODO - this is when a class is defined within a function
342+ # It's unusual but should probably be handled in the future.
343+ # Handling this use case would require some code reorganziation.
344+ # Take a look at class_in_function.js to better understand.
345+ logging .warning ("Skipping class defined within a function!" )
335346
336347 line_number = lineno (tree )
337348 calls = make_calls (this_scope_body )
0 commit comments