node-source-walk is a JavaScript utility library designed for synchronously traversing Abstract Syntax Trees (ASTs) or raw source code strings. It allows developers to apply a callback function to every node within the AST, with the crucial capability to halt the traversal prematurely using `stopWalking()`. The current stable version is 7.0.1. Releases tend to align with Node.js LTS updates, primarily dropping support for older Node.js versions. A key differentiator is its flexibility in supporting both top-down (`walk`, `traverse`) and bottom-up (`moonwalk`) traversals, accepting either source code or a pre-parsed AST, and offering the option to replace its default `@babel/parser` with a custom parser.
npm install node-source-walkVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate the Walker class, traverse source code, identify specific AST node types (like 'FunctionDeclaration' or 'JSXElement'), and efficiently stop the traversal once a desired node is found. It also shows how to configure the internal parser with custom plugins like 'jsx'.
Upgrade your Node.js runtime to version 18 or newer. If an upgrade is not possible, pin `node-source-walk` to a version compatible with your Node.js environment (e.g., `<7.0.0` for Node.js 16).
Refactor code that directly called `shouldStop` or `reverseTraverse`. Instead, use the public `stopWalking()` method to halt traversal. The `moonwalk` method provides public access to reverse traversal functionality.
Upgrade your Node.js runtime to version 14 or newer, ideally to Node.js 18+ to be compatible with the latest major versions.
Verify that your custom parser adheres to the expected `.parse(sourceString)` signature and returns a compatible AST structure. Consult `@babel/parser`'s documentation for AST shape reference.
Use default import for ESM (`import Walker from 'node-source-walk';`) or direct `require` assignment for CommonJS (`const Walker = require('node-source-walk');`).Initialize the `Walker` with `plugins` option to enable required `@babel/parser` plugins, for example: `new Walker({ plugins: ['jsx', 'typescript'] })`.Upgrade your Node.js runtime to version 18 or newer. Check your project's `engines` field in `package.json` for compatibility.
No dependency data recorded yet.