{"id":13560396,"url":"https://github.com/sxzz/ast-walker-scope","last_synced_at":"2025-09-30T03:32:09.887Z","repository":{"id":50472675,"uuid":"519169501","full_name":"sxzz/ast-walker-scope","owner":"sxzz","description":"Traverse Babel AST with scope information.","archived":false,"fork":false,"pushed_at":"2024-10-29T18:24:18.000Z","size":485,"stargazers_count":13,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-29T18:36:55.716Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/sxzz.png","metadata":{"funding":{"github":["sxzz"]},"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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}},"created_at":"2022-07-29T10:13:33.000Z","updated_at":"2024-09-26T10:18:12.000Z","dependencies_parsed_at":"2022-08-30T22:31:30.710Z","dependency_job_id":"6f08a27b-9c15-4d31-b9c1-23e883fda50c","html_url":"https://github.com/sxzz/ast-walker-scope","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sxzz%2Fast-walker-scope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sxzz%2Fast-walker-scope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sxzz%2Fast-walker-scope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sxzz%2Fast-walker-scope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sxzz","download_url":"https://codeload.github.com/sxzz/ast-walker-scope/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232180984,"owners_count":18484413,"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","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":[],"created_at":"2024-08-01T13:00:43.240Z","updated_at":"2025-09-30T03:32:09.881Z","avatar_url":"https://github.com/sxzz.png","language":"TypeScript","funding_links":["https://github.com/sponsors/sxzz"],"categories":["TypeScript"],"sub_categories":[],"readme":"# ast-walker-scope\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![Unit Test][unit-test-src]][unit-test-href]\n\nTraverse Babel AST with scope information.\n\nInherited from [estree-walker](https://github.com/Rich-Harris/estree-walker).\n\n## Install\n\n```bash\nnpm i ast-walker-scope\n```\n\n## Usage\n\n### Basic Example\n\nFor a real example, you can refer to [example.ts](./example.ts)\n\n```ts\nimport { walk } from 'ast-walker-scope'\n\nconst code = `\nconst a = 'root level'\n\n{\n  const a = 'second level'\n  let secondLevel = true\n  console.log(a, secondLevel)\n}\n\nvar err = undefined\ntry {\n} catch (err) {\n  console.log(err)\n}\n\nconsole.log(a)\n`.trim()\n\nwalk(code, {\n  leave(this, node) {\n    if (node.type === 'CallExpression') {\n      console.log(`\\nLevel: ${this.level}`)\n      for (const [name, node] of Object.entries(this.scope)) {\n        console.log(\n          `variable ${name} is located at line ${node.loc?.start.line}, column ${node.loc?.start.column}`,\n        )\n      }\n    }\n  },\n})\n```\n\nOutput:\n\n```\nLevel: 2\nvariable a is located at line 4, column 8\nvariable secondLevel is located at line 5, column 6\n\nLevel: 2\nvariable a is located at line 1, column 6\nvariable err is located at line 12, column 9\n\nLevel: 1\nvariable a is located at line 1, column 6\nvariable err is located at line 9, column 4\n```\n\n## Typings\n\n```ts\nexport type Scope = Record\u003cstring, Node\u003e\nexport interface HookContext extends WalkerContext {\n  // inherited from estree-walker\n  skip: () =\u003e void\n  remove: () =\u003e void\n  replace: (node: Node) =\u003e void\n\n  // arguments of estree-walker hook\n  parent: Node\n  key: string\n  index: number\n\n  // scope info\n  scope: Scope\n  scopes: Scope[]\n  level: number\n}\n```\n\n## Sponsors\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg\"\u003e\n    \u003cimg src='https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg'/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Credits\n\n- [@vue/reactivity-transform](https://github.com/vuejs/core/blob/v3.2.37/packages/reactivity-transform/src/reactivityTransform.ts) - almost copy-like referenced\n\n## License\n\n[MIT](./LICENSE) License © 2022-PRESENT [三咲智子](https://github.com/sxzz)\n\n\u003c!-- Badges --\u003e\n\n[npm-version-src]: https://img.shields.io/npm/v/ast-walker-scope.svg\n[npm-version-href]: https://npmjs.com/package/ast-walker-scope\n[npm-downloads-src]: https://img.shields.io/npm/dm/ast-walker-scope\n[npm-downloads-href]: https://www.npmcharts.com/compare/ast-walker-scope?interval=30\n[unit-test-src]: https://github.com/sxzz/ast-walker-scope/actions/workflows/unit-test.yml/badge.svg\n[unit-test-href]: https://github.com/sxzz/ast-walker-scope/actions/workflows/unit-test.yml\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsxzz%2Fast-walker-scope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsxzz%2Fast-walker-scope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsxzz%2Fast-walker-scope/lists"}