Is there any way to delete specific type node from AST? (for example, i want to delete all Expr Statements) Or maybe there is a way to replace it with empty ast.Expr node?
I didnt find any documentation about it so any help would be appreciated. Thanks in advance!
UPD:
func find_node(file *ast.File) {
ast.Inspect(file, func(node ast.Node) bool {
switch x := node.(type) {
case *ast.ExprStmt:
var e ast.Expr
e = x.X
fmt.Printf("Expression found: %s
", e)
}
return true
})
}
You can try the astutil package. See the delete example in the tests at rewrite_test.go.