benjamn / ast-types

Esprima-compatible implementation of the Mozilla JS Parser API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does anyone know how to distinguish whether it is the same variable in ast?

643104191 opened this issue · comments

img

const { parse, print, visit } = require('recast')

const ast = parse(`function test(samename){
  samename(123);
  var b = {
    c: function (samename){
      samename(456)
    },
    d: function() {
      samename(789)
    }
  }
}`)

const funcAst = ast.program.body[0]

const arg = funcAst.params[0]

console.log(arg)

visit(funcAst, {
  visitCallExpression(path) {
    console.log(path.value.callee)
    this.traverse(path)
  }
})