Subscribe on changes!

Provide a `visit` function in @vue/compiler-dom

avatar
Mar 26th 2021

What problem does this feature solve?

It's very often to have a "visit pattern" implementation in a AST parser. Currently, I can't find a proper way to modify(add or remove node) the AST, It would be really convenient to modify the parsed AST return by the parse function.

What does the proposed API look like?

I'd like to see the API just like the graphql-js's one. https://graphql.org/graphql-js/language/#visit

import { parse, visit } from '@vue/compiler-dom'

const ast = parse(...)

visit(ast, ...)
avatar
Mar 26th 2021
import { parse, transform } from '@vue/compiler-dom'

const ast = parse(...)

transform(ast, {
  nodeTransforms: [...]
})

Please read the source type definitions for transform options usage.

avatar
Nov 14th 2021
import { parse, transform } from '@vue/compiler-dom'

const ast = parse(...)

transform(ast, {
  nodeTransforms: [...]
})

Please read the source type definitions for transform options usage.

Is there a generate method to convert ast to source string?

like this

const ast = parse(`<div>abc</div>`)

generate(ast) //  `<div>abc</div>`
avatar
Nov 14th 2021

Yes, please read the source code.