{"name":"node-source-walk","version":"7.0.1","description":"Execute a callback on every node of a source code's AST and stop walking when you see fit","main":"index.js","scripts":{"lint":"xo","fix":"xo --fix","uvu":"uvu test -i fixtures","test":"npm run lint && npm run uvu","test:ci":"c8 npm run uvu"},"repository":{"type":"git","url":"git+https://github.com/dependents/node-source-walk.git"},"keywords":["ast","traversal","acorn","static analysis","source code","walker","jsx"],"author":{"name":"Joel Kemp","email":"joel@mrjoelkemp.com"},"license":"MIT","bugs":{"url":"https://github.com/dependents/node-source-walk/issues"},"homepage":"https://github.com/dependents/node-source-walk","engines":{"node":">=18"},"dependencies":{"@babel/parser":"^7.26.7"},"devDependencies":{"c8":"^10.1.3","sinon":"^19.0.2","uvu":"^0.5.6","xo":"^0.60.0"},"xo":{"space":true,"ignores":["test/fixtures/*"],"rules":{"arrow-body-style":"off","capitalized-comments":"off","comma-dangle":["error","never"],"curly":["error","multi-line"],"operator-linebreak":["error","after"],"object-curly-spacing":["error","always"],"space-before-function-paren":["error","never"],"unicorn/prefer-module":"off","unicorn/prefer-node-protocol":"off","unicorn/prefer-top-level-await":"off","unicorn/prevent-abbreviations":"off"}},"_id":"node-source-walk@7.0.1","gitHead":"b29553f5bc7c1a61bdd879e9ba66fa68fd477a78","_nodeVersion":"20.18.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-3VW/8JpPqPvnJvseXowjZcirPisssnBuDikk6JIZ8jQzF7KJQX52iPFX4RYYxLycYH7IbMRSPUOga/esVjy5Yg==","shasum":"3e4ab8d065377228fd038af7b2d4fb58f61defd3","tarball":"http://registry-npm.ywwl.com/node-source-walk/download/node-source-walk-7.0.1.tgz","fileCount":4,"unpackedSize":9284,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDMRDGFugcL2Xumu3v1fPET76H1ODTlVbNRYMaHoiu7GgIgKK5jo7WhAB3RiR74YqA9aaK7ZjbHDa/N/VuwNBXopLA="}],"size":3850,"noattachment":false,"key":"/node-source-walk/-/node-source-walk-7.0.1.tgz"},"_npmUser":{"name":"xhmikosr","email":"xhmikosr@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/node-source-walk_7.0.1_1738256551053_0.03502370850557335"},"_hasShrinkwrap":false,"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```js\nconst Walker = require('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\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":1738256551201,"maintainers":[{"name":"pahen","email":"patrik.henningsson@gmail.com"},{"name":"mrjoelkemp","email":"mrjoelkemp@gmail.com"},{"name":"xhmikosr","email":"xhmikosr@gmail.com"}],"_cnpm_publish_time":1738256551201,"dist-tags":{"latest":"8.0.0"}}