{"id":29423726,"url":"https://github.com/syntax-tree/estree-util-scope","last_synced_at":"2025-07-28T01:35:13.308Z","repository":{"id":255375720,"uuid":"849412119","full_name":"syntax-tree/estree-util-scope","owner":"syntax-tree","description":"Check what’s defined in an estree scope","archived":false,"fork":false,"pushed_at":"2024-09-19T09:59:14.000Z","size":11,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-07-12T07:38:09.104Z","etag":null,"topics":["ecmascript","estree","javascript","scope"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","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/syntax-tree.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},"funding":{"github":"unifiedjs","open_collective":"unified"}},"created_at":"2024-08-29T14:48:29.000Z","updated_at":"2025-05-15T16:23:07.000Z","dependencies_parsed_at":"2024-08-29T16:34:00.370Z","dependency_job_id":"b5ff3649-b02e-456e-bf23-d15c212751af","html_url":"https://github.com/syntax-tree/estree-util-scope","commit_stats":null,"previous_names":["syntax-tree/estree-util-scope"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/estree-util-scope","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Festree-util-scope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Festree-util-scope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Festree-util-scope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Festree-util-scope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/estree-util-scope/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Festree-util-scope/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267451156,"owners_count":24089293,"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-07-27T02:00:11.917Z","response_time":82,"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":["ecmascript","estree","javascript","scope"],"created_at":"2025-07-12T07:37:59.900Z","updated_at":"2025-07-28T01:35:13.254Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","readme":"# estree-util-scope\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[estree][] utility to check what’s defined in a scope.\n\n## Contents\n\n* [What is this?](#what-is-this)\n* [When should I use this?](#when-should-i-use-this)\n* [Install](#install)\n* [Use](#use)\n* [API](#api)\n  * [`Scope`](#scope)\n  * [`Visitors`](#visitors)\n  * [`createVisitors()`](#createvisitors)\n* [Examples](#examples)\n  * [Example: just the top scope](#example-just-the-top-scope)\n* [Compatibility](#compatibility)\n* [Related](#related)\n* [Security](#security)\n* [Contribute](#contribute)\n* [License](#license)\n\n## What is this?\n\nThis package is a utility that tracks what’s defined in a scope.\n\n## When should I use this?\n\nIf you are walking an estree already and want to find out what’s defined,\nuse this.\nIf you have more complex scoping needs,\nsee [`eslint-scope`][github-eslint-scope].\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install estree-util-scope\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {createVisitors} from 'https://esm.sh/estree-util-scope@1'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {createVisitors} from 'https://esm.sh/estree-util-scope@1?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\nSay we have the following `example.js`:\n\n```js\n/**\n * @import {Program} from 'estree'\n */\n\nimport {Parser} from 'acorn'\nimport {createVisitors} from 'estree-util-scope'\nimport {walk} from 'estree-walker'\n\nconst tree = /** @type {Program} */ (\n  Parser.parse('import {a} from \"b\"; const c = 1', {\n    ecmaVersion: 'latest',\n    sourceType: 'module'\n  })\n)\nconst visitors = createVisitors()\n\nwalk(tree, {enter: visitors.enter, leave: visitors.exit})\n\nconsole.log(visitors.scopes.at(-1))\n```\n\n…now running `node example.js` yields:\n\n```js\n{ block: false, defined: [ 'a', 'c' ] }\n```\n\n## API\n\n### `Scope`\n\nScope.\n\n###### Fields\n\n* `block` (`boolean`)\n  — whether this is a block scope or not;\n  blocks are things made by `for` and `try` and `if`;\n  non-blocks are functions and the top-level scope\n* `defined` (`Array\u003cstring\u003e`)\n  — identifiers that are defined in this scope\n\n### `Visitors`\n\nState to track what’s defined;\ncontains `enter`, `exit` callbacks you must call and `scopes`.\n\n###### Fields\n\n* `enter` (`(node: Node) =\u003e undefined`)\n  — callback you must call when entering a node\n* `exit` (`(node: Node) =\u003e undefined`)\n  — callback you must call when exiting (leaving) a node\n* `scopes` (`[topLevel: Scope, ...rest: Scope[]]`)\n  — list of scopes;\n  the first scope is the top-level scope;\n  the last scope is the current scope\n\n### `createVisitors()`\n\nCreate state to track what’s defined.\n\n###### Parameters\n\nThere are no parameters.\n\n###### Returns\n\nState (`Visitors`).\n\n## Examples\n\n### Example: just the top scope\n\nSometimes, you only care about a top-scope.\nOr otherwise want to skip a node.\nHow to do this depends on how you walk the tree.\nWith `estree-walker`,\nyou can skip by calling `this.skip`.\n\n```js\n/**\n * @import {Program} from 'estree'\n */\n\nimport {Parser} from 'acorn'\nimport {createVisitors} from 'estree-util-scope'\nimport {walk} from 'estree-walker'\n\nconst tree = /** @type {Program} */ (\n  Parser.parse(\n    'function a(b) { var c = 1; if (d) { var e = 2 } }; if (f) { var g = 2 }',\n    {ecmaVersion: 'latest'}\n  )\n)\nconst visitors = createVisitors()\n\nwalk(tree, {\n  enter(node) {\n    visitors.enter(node)\n\n    if (\n      node.type === 'ArrowFunctionExpression' ||\n      node.type === 'FunctionDeclaration' ||\n      node.type === 'FunctionExpression'\n    ) {\n      this.skip()\n      visitors.exit(node) // Call the exit handler manually.\n    }\n  },\n  leave: visitors.exit\n})\n\nconsole.log(visitors.scopes.at(-1))\n```\n\n…yields:\n\n```js\n{ block: false, defined: [ 'a', 'g' ] }\n```\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `estree-util-scope@1`,\ncompatible with Node.js 16.\n\n## Related\n\n## Security\n\nThis package is safe.\n\n## Contribute\n\nSee [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get\nstarted.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/syntax-tree/estree-util-scope/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/estree-util-scope/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/estree-util-scope.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/estree-util-scope\n\n[downloads-badge]: https://img.shields.io/npm/dm/estree-util-scope.svg\n\n[downloads]: https://www.npmjs.com/package/estree-util-scope\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=estree-util-scope\n\n[size]: https://bundlejs.com/?q=estree-util-scope\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esmsh]: https://esm.sh\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[estree]: https://github.com/estree/estree\n\n[github-eslint-scope]: https://github.com/eslint/eslint-scope\n","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Festree-util-scope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Festree-util-scope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Festree-util-scope/lists"}