swc-walk
v1.0.0-rc.2
Published
Walk an AST from SWC and visit each node type.
Downloads
310
Maintainers
Readme
swc-walk
Walk an AST from SWC and visit each node type.
Requirements
- AST is as defined by
@swc/types
.
Example
swc-walk
wraps acorn-walk
walkers.
import { simple } from 'swc-walk'
import { parseSync } from '@swc/core'
import assert from 'node:assert/strict'
type WalkState = {
[k: string]: string
}
const state = {
search: 'const foo',
}
const ast = parseSync('const foo: string = "bar"', { syntax: 'typescript' })
simple<WalkState>(
ast,
{
VariableDeclaration(node, state) {
assert.equal(node.type, 'VariableDeclaration')
assert.ok(typeof state.search === 'string')
},
},
undefined,
state,
)