1

How can I remove the nodes in a ast tree using esprima? Here is my code:

import esprima

class MyVisitor(esprima.NodeVisitor):

    def visit_ExpressionStatement(self, node):
        return None


visitor = MyVisitor()

tree = esprima.parse("""
alert('first alert');
function foo() {
    var i2= 20;
    alert('foo function');
}
""")

visitor.visit(tree)

print(tree)

I want to remove all ExpressionStatement nodes from this ast tree but I am not sure how to do it. Please help. Thank you!

JJ Cauton
  • 109
  • 7

0 Answers0