{"id":19373,"library":"babel-walk","title":"babel-walk","description":"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).","status":"active","version":"3.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/pugjs/babel-walk","tags":["javascript"],"install":[{"cmd":"npm install babel-walk","lang":"bash","label":"npm"},{"cmd":"yarn add babel-walk","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-walk","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"In v3, simple is curried: first call returns a function that takes (node, state). The old (node, visitors, state) signature is gone.","wrong":"const walk = require('babel-walk'); walk.simple(visitors)(node, state); // v3 curried, use walk.simple(visitors)(node, state) not walk.simple(node, visitors, state)","symbol":"simple","correct":"import { simple } from 'babel-walk'"},{"note":"All walkers are named exports from the package root. No subpath exports prior to v3; always import from 'babel-walk'.","wrong":"const ancestor = require('babel-walk/ancestor'); // wrong path; ancestor is a named export from 'babel-walk'","symbol":"ancestor","correct":"import { ancestor } from 'babel-walk'"},{"note":"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.","wrong":"const recursive = require('babel-walk').recursive; // correct in CJS, but note the curried signature","symbol":"recursive","correct":"import { recursive } from 'babel-walk'"}],"quickstart":{"code":"import { parse } from '@babel/parser';\nimport { simple } from 'babel-walk';\n\nconst code = 'const x = 1;';\nconst ast = parse(code, { sourceType: 'module' });\n\n// Create a walker (curried: visitors first, then node+state)\nconst walker = simple({\n  Identifier(node, state) {\n    console.log(`Found identifier: ${node.name} at line ${node.loc.start.line}`);\n  },\n  FunctionDeclaration(node, state) {\n    state.functions.push(node.id.name);\n  },\n});\n\nconst state = { functions: [] };\nwalker(ast, state);\nconsole.log('Functions:', state.functions);","lang":"typescript","description":"Parses Babel AST and uses simple walker with cached visitors; demonstrates curried API and state passing."},"warnings":[{"fix":"Change to walk.simple(visitors)(node, state) or destructure import { simple } and call simple(visitors)(node, state).","message":"v3.0.0: All functions are now curried. Old call signature walk.simple(node, visitors, state) no longer works.","severity":"breaking","affected_versions":"<=2.0.0"},{"fix":"Replace require('babylon-walk') with require('babel-walk') or import from 'babel-walk'.","message":"v2.0.0: Package renamed from babylon-walk to babel-walk; old package deprecated.","severity":"breaking","affected_versions":"<=1.0.0"},{"fix":"Use separate visitor functions for each node type or use an alias like Expression.","message":"Union syntax for visitors (e.g., 'NumberLiteral|StringLiteral'(node, state) {}) is not supported.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Always pass a state object (can be empty object {}) to ancestor walker to avoid confusing defaults.","message":"State 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.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use const { simple } = require('babel-walk'); then simple(visitors)(node, state);","cause":"Using CommonJS require with default import expecting ESM default export, or using old non-curried API in v3.","error":"TypeError: walk.simple is not a function"},{"fix":"Run npm install babel-walk and ensure import path is 'babel-walk' not 'babylon-walk'.","cause":"Package not installed or using old package name babylon-walk.","error":"Cannot find module 'babel-walk'"},{"fix":"Define separate visitors for each node type, or use a broader alias like Declaration.","cause":"Union syntax like 'FunctionDeclaration|VariableDeclaration' used; not supported.","error":"TypeError: Cannot read properties of undefined (reading 'Function')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}