{"name":"node-source-walk","version":"7.0.2","keywords":["ast","traversal","acorn","static analysis","source code","walker","jsx"],"author":{"name":"Joel Kemp","email":"joel@mrjoelkemp.com"},"license":"MIT","_id":"node-source-walk@7.0.2","maintainers":[{"name":"pahen","email":"patrik.henningsson@gmail.com"},{"name":"mrjoelkemp","email":"mrjoelkemp@gmail.com"},{"name":"xhmikosr","email":"xhmikosr@gmail.com"}],"homepage":"https://github.com/dependents/node-source-walk","bugs":{"url":"https://github.com/dependents/node-source-walk/issues"},"xo":{"rules":{"curly":["error","multi-line"],"comma-dangle":["error","never"],"arrow-body-style":"off","operator-linebreak":["error","after"],"capitalized-comments":"off","object-curly-spacing":["error","always"],"unicorn/prefer-module":"off","space-before-function-paren":["error","never"],"unicorn/prefer-node-protocol":"off","unicorn/prevent-abbreviations":"off","unicorn/prefer-top-level-await":"off"},"space":true,"ignores":["test/fixtures/*"]},"dist":{"shasum":"b075259cb40c3158570447be7bd4decffd207694","tarball":"http://registry-npm.ywwl.com/node-source-walk/download/node-source-walk-7.0.2.tgz","fileCount":4,"integrity":"sha512-71kFFjYaSshDTA8/a2HiTYPLdASWjLJxUyJxGE+ffxU+KhxSBtM9kiLUX+R2yooFdSFKMFpi4n3PFtDy6qXv8A==","signatures":[{"sig":"MEQCIGPPDEgALuPVKPwT/5Z5VRQ8VtYdtSEBR0j85x31e/hMAiBeceYls2b94WgKXctOTW2pI65Ga3oWxJewjQjpQlFRUw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":10266,"size":4079,"noattachment":false,"key":"/node-source-walk/-/node-source-walk-7.0.2.tgz"},"main":"index.js","engines":{"node":">=18"},"gitHead":"d2a78227a86ab2343c5fc8ba52bfe0817bab1d5b","scripts":{"fix":"xo --fix","uvu":"uvu test -i fixtures","lint":"xo","test":"npm run lint && npm run uvu","test:ci":"c8 npm run uvu"},"_npmUser":{"name":"xhmikosr","email":"xhmikosr@gmail.com"},"repository":{"url":"git+https://github.com/dependents/node-source-walk.git","type":"git"},"_npmVersion":"11.12.1","description":"Execute a callback on every node of a source code's AST and stop walking when you see fit","directories":{},"_nodeVersion":"24.15.0","dependencies":{"@babel/parser":"^7.29.0"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.1.3","xo":"^0.60.0","uvu":"^0.5.6","sinon":"^19.0.5"},"_npmOperationalInternal":{"tmp":"tmp/node-source-walk_7.0.2_1777101880207_0.8052793099027253","host":"s3://npm-registry-packages-npm-production"},"readme":"# node-source-walk\n\n[![CI](https://img.shields.io/github/actions/workflow/status/dependents/node-source-walk/ci.yml?branch=main&label=CI&logo=github)](https://github.com/dependents/node-source-walk/actions/workflows/ci.yml?query=branch%3Amain)\n[![npm version](https://img.shields.io/npm/v/node-source-walk?logo=npm&logoColor=fff)](https://www.npmjs.com/package/node-source-walk)\n[![npm downloads](https://img.shields.io/npm/dm/node-source-walk)](https://www.npmjs.com/package/node-source-walk)\n\n> Synchronously execute a callback on every node of a file's AST and stop walking whenever you see fit.\n\n```sh\nnpm install node-source-walk\n```\n\n## Usage\n\n## ESM\n\n```js\nimport Walker from 'node-source-walk';\n\nconst walker = new Walker();\n\n// Assume src is the string contents of myfile.js\n// or the AST of an outside parse of myfile.js\nwalker.walk(src, node => {\n  if (node.type === whateverImLookingFor) {\n    // No need to keep traversing since we found what we wanted\n    walker.stopWalking();\n  }\n});\n```\n\n### CommonJS\n\n```js\nconst { default: Walker } = require('node-source-walk');\n\nconst walker = new Walker();\n// ...\n```\n\nBy default, Walker will use `@babel/parser` (supporting ES6, JSX, Flow, and all other available `@babel/parser` plugins) and the `sourceType: module`, but you can change any of the defaults as follows:\n\n```js\nconst walker = new Walker({\n  sourceType: 'script',\n  // If you don't like experimental plugins\n  plugins: [\n    'jsx',\n    'flow'\n  ]\n});\n```\n\n* The supplied options are passed through to the parser, so you can configure it according to `@babel/parser`'s [documentation](https://babeljs.io/docs/en/babel-parser.html).\n\n## Swap out the parser\n\nIf you want to supply your own parser, you can do:\n\n```js\nconst walker = new Walker({\n  parser: mySweetParser\n});\n```\n\n* The custom parser must have a `.parse` method that takes in a string and returns an object/AST.\n* All of the other options supplied to the Walker constructor will be passed along as parser options to your chosen parser.\n\n## API\n\n### `walk(src, callback)`\n\n* Recursively walks the given `src` from top to bottom\n* `src`: the contents of a file **or** its (already parsed) AST\n* `callback`: a function that is called for every visited node\n  * The argument passed to `callback` will be the currently visited node.\n\n### `moonwalk(node, callback)`\n\n* Recursively walks up an AST starting from the given node. This is a traversal that's in the opposite direction of `walk` and `traverse`\n* `node`: a valid AST node\n* `callback`: a function that is called for every node (specifically via visiting the parent(s) of every node recursively)\n  * The argument passed to `callback` will be the currently visited node.\n\n### `stopWalking()`\n\n* Halts further walking of the AST until another manual call of `walk` or `moonwalk`\n* This is super-beneficial when dealing with large source files (or ASTs)\n\n### `traverse(node, callback)`\n\n* Allows you to traverse an AST node and execute a callback on it\n* Callback should expect the first argument to be an AST node, similar to `walk`'s callback\n\n### `parse(src)`\n\n* Uses the options supplied to Walker to parse the given source code string and return its AST using the configured parser (or `@babel/parser` by default).\n\n## License\n\n[MIT](LICENSE)\n","publish_time":1777101880351,"_cnpm_publish_time":1777101880351,"dist-tags":{"latest":"8.0.0"}}