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

partial visit #943

Open
retorquere opened this issue Sep 7, 2023 · 1 comment
Open

partial visit #943

retorquere opened this issue Sep 7, 2023 · 1 comment

Comments

@retorquere
Copy link

I want to visit an AST, but exclude CallExpression arguments. How can I do this? Given the script below, I'm missing almost all identifiers

const { parse } = require('recast')
const { visit } = require('ast-types')

const src = `
[
    () => ((x() ? y() : z()) + y()).len() + (auth(creator).lower(1) + year()).len(">", 0).postfix(_) + title().len(">", 0).lower() + other(),
    () => x()
]
`

const idents = {
  visitIdentifier(path) {
    console.log(path.node.name)
    this.traverse(path)
  },
  visitCallExpression(path) {
    this.traverse(path.get('callee'))
    // this.traverse(path)
  },
}

let ast = parse(src)
ast = visit(ast, idents)
@retorquere
Copy link
Author

Could it be because arguments isn't really a node type, but simply an array of nodes? path.get('arguments') doesn't have a type.

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

No branches or pull requests

1 participant