Registry / babel-walk

babel-walk

JSON →
library3.0.1jsnpmunverified

Lightweight AST traversal library for Babel ASTs, v3.0.1 (released 2023). Provides simple, ancestor, and recursive walk functions that are significantly faster than babel-traverse (~8-16x). Key differentiators: curried API (since v3) for improved TypeScript inference and caching of visitors; no union syntax support; designed for non-transformational walks where performance matters. Release cadence is irregular, with major breaking changes in v2 (rename from babylon-walk, dropped Node <10) and v3 (curried functions).

npm install babel-walk
INSTALL
IMPORT
SIG · BABEL-WALK
B
babel-walk
javascriptv3.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

simple
import { simple } from 'babel-walk'
const walk = require('babel-walk'); walk.simple(visitors)(node, state); // v3 curried, use walk.simple(visitors)(node, state) not walk.simple(node, visitors, state)
In v3, simple is curried: first call returns a function that takes (node, state). The old (node, visitors, state) signature is gone.
ancestor
import { ancestor } from 'babel-walk'
const ancestor = require('babel-walk/ancestor'); // wrong path; ancestor is a named export from 'babel-walk'
All walkers are named exports from the package root. No subpath exports prior to v3; always import from 'babel-walk'.
recursive
import { recursive } from 'babel-walk'
const recursive = require('babel-walk').recursive; // correct in CJS, but note the curried signature
recursive is also curried in v3: first call returns (node, state) => void. State is mandatory; if omitted, it defaults to the ancestors array in ancestor walker.

Parses Babel AST and uses simple walker with cached visitors; demonstrates curried API and state passing.

import { parse } from '@babel/parser'; import { simple } from 'babel-walk'; const code = 'const x = 1;'; const ast = parse(code, { sourceType: 'module' }); // Create a walker (curried: visitors first, then node+state) const walker = simple({ Identifier(node, state) { console.log(`Found identifier: ${node.name} at line ${node.loc.start.line}`); }, FunctionDeclaration(node, state) { state.functions.push(node.id.name); }, }); const state = { functions: [] }; walker(ast, state); console.log('Functions:', state.functions);
Debug
Known issues
breakingv3.0.0: All functions are now curried. Old call signature walk.simple(node, visitors, state) no longer works.
fix
Change to walk.simple(visitors)(node, state) or destructure import { simple } and call simple(visitors)(node, state).
affects: <=2.0.0
breakingv2.0.0: Package renamed from babylon-walk to babel-walk; old package deprecated.
fix
Replace require('babylon-walk') with require('babel-walk') or import from 'babel-walk'.
affects: <=1.0.0
deprecatedUnion syntax for visitors (e.g., 'NumberLiteral|StringLiteral'(node, state) {}) is not supported.
fix
Use separate visitor functions for each node type or use an alias like Expression.
affects: >=2.0.0
gotchaState argument is required in ancestor walker but defaulted to ancestors array if omitted. In v2, falsy state was replaced by ancestors; in v3, state is always required.
fix
Always pass a state object (can be empty object {}) to ancestor walker to avoid confusing defaults.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: walk.simple is not a function
Using CommonJS require with default import expecting ESM default export, or using old non-curried API in v3.
fix
Use const { simple } = require('babel-walk'); then simple(visitors)(node, state);
Cannot find module 'babel-walk'
Package not installed or using old package name babylon-walk.
fix
Run npm install babel-walk and ensure import path is 'babel-walk' not 'babylon-walk'.
TypeError: Cannot read properties of undefined (reading 'Function')
Union syntax like 'FunctionDeclaration|VariableDeclaration' used; not supported.
fix
Define separate visitors for each node type, or use a broader alias like Declaration.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
babel-walk — npm install babel-walk · libregistry