Skip to content

Commit

Permalink
Abstract syntax tree: disable tree construction due to max recursion
Browse files Browse the repository at this point in the history
depth errors
  • Loading branch information
wichmannpas committed Jan 2, 2018
1 parent c3aba12 commit 22a870f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
52 changes: 28 additions & 24 deletions files/javascript_file.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
from typing import Union

import pyjsparser
from pyjsparser import JsSyntaxError
# import pyjsparser
# from pyjsparser import JsSyntaxError

from base.utils import normalize_data
from files.file import File
Expand Down Expand Up @@ -31,25 +31,29 @@ def normalized_content(self) -> Union[bytes, None]:
"""
The content of this static file normalized for this file type.
"""
try:
content = self.raw_content.decode()
except UnicodeDecodeError:
return None

if not self.has_usual_file_name_extension:
# skip parsing if file extension does not indicate javascript
return None

try:
parsed = pyjsparser.parse(content)

return normalize_data(parsed)
except (JsSyntaxError, TypeError, ValueError):
logging.warning(
'failed to parse javascript file %s. Skipping abstract syntax tree construction',
self.file_name)
parsed = content
try:
return normalize_data(parsed)
except (TypeError, ValueError):
return None
# TODO: fix abstract syntax tree issues and reuse code
return self.raw_content

# TODO: max recursion depth reached easily
# try:
# content = self.raw_content.decode()
# except UnicodeDecodeError:
# return None

# if not self.has_usual_file_name_extension:
# # skip parsing if file extension does not indicate javascript
# return None

# try:
# parsed = pyjsparser.parse(content)

# return normalize_data(parsed)
# except (JsSyntaxError, TypeError, ValueError):
# logging.warning(
# 'failed to parse javascript file %s. Skipping abstract syntax tree construction',
# self.file_name)
# parsed = content
# try:
# return normalize_data(parsed)
# except (TypeError, ValueError):
# return None
1 change: 0 additions & 1 deletion update_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ def index(arguments: Namespace):
)

index(parser.parse_args())

0 comments on commit 22a870f

Please sign in to comment.