benjamn / recast

JavaScript syntax tree transformer, nondestructive pretty-printer, and automatic source map generator
MIT License
4.99k stars 349 forks source link

How to get the parent node? #1282

Open SandZn opened 1 year ago

SandZn commented 1 year ago

Hi, how can I get the parent node when I visit some node on AST? It is now undefined. For example,

visitExpressionStatement: function(node){
      console.log(node.parent)
      console.log(node.parentNode)
      console.log(node.getParentNode())
}

None of them works.