Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue while parsing js code #53

Open
r0oth3x49 opened this issue Sep 13, 2021 · 0 comments
Open

Issue while parsing js code #53

r0oth3x49 opened this issue Sep 13, 2021 · 0 comments
Labels

Comments

@r0oth3x49
Copy link

r0oth3x49 commented Sep 13, 2021

first of all thank you so much for creating such a great project I 'm facing an issue while trying to parse the attach js code. it throws an NoneType Exception, the js code is attached below.

javascript code which causes the error

Code to reproduce the error

>>> import js2xml
>>> p = js2xml.parse('new Error')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/env/lib/python3.9/site-packages/js2xml/__init__.py", line 18, in parse
    xml = _visitor.visit(tree)
...
  File "/tmp/env/lib/python3.9/site-packages/js2xml/xmlvisitor.py", line 402, in visit_NewExpr
    for arg in node.args:
TypeError: 'NoneType' object is not iterable
>>> 

what i did is simply added an if conditioni in xmlvisitor on line number 402 and it fixed the above error but i don't know if it's really a good fix.

def visit_NewExpr(self, node):
        newel = E.new()
        newel.extend(self.visit(node.identifier))
        arguments = E.arguments()
        if node.args: # check if none before starting a loop as loop can't be run on NoneType objects
            for arg in node.args:
                arguments.extend(self.visit(arg))
            newel.append(arguments)
        return [newel]

Edit
The issue i mistakenly created on calmjs/calmjs.parse#40 but he explained it very well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants