{"id":13773491,"url":"https://github.com/dependents/node-source-walk","last_synced_at":"2025-12-22T23:04:52.204Z","repository":{"id":15156642,"uuid":"17884222","full_name":"dependents/node-source-walk","owner":"dependents","description":"Execute a callback on every node of a source code's AST and stop walking whenever you see fit.","archived":false,"fork":false,"pushed_at":"2025-11-01T02:01:58.000Z","size":511,"stargazers_count":63,"open_issues_count":3,"forks_count":7,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-11-17T00:25:42.671Z","etag":null,"topics":["ast","javascript","traverse"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dependents.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-03-18T22:24:51.000Z","updated_at":"2025-11-03T21:50:32.000Z","dependencies_parsed_at":"2024-01-15T07:14:48.336Z","dependency_job_id":"3f467677-e7e3-455d-8730-7e00517b4aa8","html_url":"https://github.com/dependents/node-source-walk","commit_stats":{"total_commits":79,"total_committers":9,"mean_commits":8.777777777777779,"dds":0.5569620253164558,"last_synced_commit":"8b63e7010939d5dd3f7b1c8dd95053bbe14bef17"},"previous_names":["mrjoelkemp/node-source-walk"],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/dependents/node-source-walk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dependents%2Fnode-source-walk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dependents%2Fnode-source-walk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dependents%2Fnode-source-walk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dependents%2Fnode-source-walk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dependents","download_url":"https://codeload.github.com/dependents/node-source-walk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dependents%2Fnode-source-walk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285511776,"owners_count":27184237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-20T02:00:05.334Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","javascript","traverse"],"created_at":"2024-08-03T17:01:16.219Z","updated_at":"2025-12-22T23:04:51.863Z","avatar_url":"https://github.com/dependents.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":["Traversal"],"readme":"# node-source-walk\n\n[![CI](https://img.shields.io/github/actions/workflow/status/dependents/node-source-walk/ci.yml?branch=main\u0026label=CI\u0026logo=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\u0026logoColor=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\u003e 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 =\u003e {\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdependents%2Fnode-source-walk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdependents%2Fnode-source-walk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdependents%2Fnode-source-walk/lists"}