{"id":18968,"library":"ast-walker-scope","title":"ast-walker-scope","description":"Traverse Babel AST with scope information. v0.9.0 is the current stable version, released with breaking changes dropping the types field and fixing a prototype pollution vulnerability. The package is ESM-only from v0.8.0, requires Node >=20.19.0, and builds on top of estree-walker. Key differentiators: scope tracking per node, support for Babel AST, and a simple hook context with scope, scopes, and level properties. Compared to estree-walker, it adds scope-aware traversal without a separate scope analysis step.","status":"active","version":"0.9.0","language":"javascript","source_language":"en","source_url":"https://github.com/sxzz/ast-walker-scope","tags":["javascript"],"install":[{"cmd":"npm install ast-walker-scope","lang":"bash","label":"npm"},{"cmd":"yarn add ast-walker-scope","lang":"bash","label":"yarn"},{"cmd":"pnpm add ast-walker-scope","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for Babel AST node type definitions and utilities.","package":"@babel/types","optional":false}],"imports":[{"note":"ESM-only since v0.8.0; no CommonJS export. Use dynamic import() if needed.","wrong":"const walk = require('ast-walker-scope')","symbol":"walk","correct":"import { walk } from 'ast-walker-scope'"},{"note":"Scope is a TypeScript type, not a value. Use `import type` for type-only imports.","wrong":"import { Scope } from 'ast-walker-scope'","symbol":"Scope","correct":"import type { Scope } from 'ast-walker-scope'"},{"note":"HookContext is a TypeScript type, not a runtime value. Must be imported as type.","wrong":"import { HookContext } from 'ast-walker-scope'","symbol":"HookContext","correct":"import type { HookContext } from 'ast-walker-scope'"}],"quickstart":{"code":"import { walk } from 'ast-walker-scope';\n\nconst code = `\nconst a = 1;\n{\n  const b = 2;\n  console.log(a, b);\n}\n`.trim();\n\nwalk(code, {\n  enter(node) {\n    console.log(`Enter: ${node.type}`);\n  },\n  leave(node) {\n    if (node.type === 'CallExpression') {\n      console.log('Scope variables:', Object.keys(this.scope));\n    }\n  },\n});\n","lang":"typescript","description":"Demonstrates basic usage of walk() with scope tracking in enter/leave hooks."},"warnings":[{"fix":"Use `import type` and ensure your tsconfig includes `node_modules/ast-walker-scope` types correctly; or install `@types/ast-walker-scope` if available.","message":"Removed types field from package.json; TypeScript types may not be resolvable without separate types export.","severity":"breaking","affected_versions":">=0.9.0"},{"fix":"Migrate to ESM syntax (`import` instead of `require`). Upgrade Node.js to >=20.19.0.","message":"Dropped CommonJS build and Node.js 18 support.","severity":"breaking","affected_versions":">=0.8.0"},{"fix":"Upgrade Node.js to >=18 or later (but note >=0.8.0 requires >=20.19.0).","message":"Dropped Node.js 16 support.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Switch to `import` syntax or use dynamic `import('ast-walker-scope')`.","message":"Default to ESM from v0.6.0; CJS require() no longer works without dynamic import.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Upgrade to v0.9.0 or later to avoid potential prototype pollution.","message":"Prototype pollution via __proto__ identifier was fixed in v0.9.0.","severity":"deprecated","affected_versions":"<0.9.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Replace `require('ast-walker-scope')` with `import { walk } from 'ast-walker-scope'` or use dynamic `import()`.","cause":"Package is ESM-only from v0.8.0 (v0.6.0 if using default ESM).","error":"ERR_REQUIRE_ESM: require() of ES Module /path/to/node_modules/ast-walker-scope/dist/index.js from /path/to/project/index.js not supported."},{"fix":"Use `import { walk } from 'ast-walker-scope'` (named import).","cause":"Incorrect import pattern (e.g., default import instead of named import).","error":"TypeError: walk is not a function"},{"fix":"Run `npm install ast-walker-scope` and ensure the import path is correct.","cause":"Package not installed or misspelled.","error":"Module not found: Can't resolve 'ast-walker-scope' in '/path/to/project'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}