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

'visitObjectProperty' option of visit function did not work #648

Open
tinycold opened this issue Nov 2, 2021 · 0 comments
Open

'visitObjectProperty' option of visit function did not work #648

tinycold opened this issue Nov 2, 2021 · 0 comments

Comments

@tinycold
Copy link

tinycold commented Nov 2, 2021

I tried to parse my code with recast, and traverse AST with ast-types.

But when I used visitObjectProperty option in visit function, it did't work.

All my code is below:

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

const rawCode = `
import Foo from "./Foo.vue"

export default {
  components: {
    Foo
  },
  data() {
    return {
      msg: 'Hello World'
    }
  }
}
`
const ast = parse(rawCode)
visit(ast, {
  visitObjectExpression(path) {
    // can access to object properties here.
    console.log(path.value.properties)
    this.traverse(path)
  },
  visitObjectProperty(path) {
    // nothing print. cannot access to object property
    console.log('------------Property-------------')
    console.log(path)
    this.traverse(path)
  }
})

Environment

node version: v16.9.1
ast-types version: v0.14.2
recast version: v0.20.5
OS: Mac OS 11.3.1

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