{
  "_id": "estree-util-scope",
  "maintainers": [
    {
      "email": "tituswormer@gmail.com",
      "name": "wooorm"
    },
    {
      "email": "keith@mcknig.ht",
      "name": "kmck"
    }
  ],
  "keywords": [
    "ast",
    "ecmascript",
    "estree",
    "javascript",
    "scope",
    "tree"
  ],
  "dist-tags": {
    "latest": "1.0.0"
  },
  "author": {
    "url": "https://wooorm.com",
    "name": "Titus Wormer",
    "email": "tituswormer@gmail.com"
  },
  "_rev": "1-7abf3fd2ecd3bccb44fc651decb373e7",
  "description": "Check what’s defined in an estree scope",
  "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<script type=\"module\">\n  import {createVisitors} from 'https://esm.sh/estree-util-scope@1?bundle'\n</script>\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<string>`)\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) => undefined`)\n  — callback you must call when entering a node\n* `exit` (`(node: Node) => 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<!-- Definitions -->\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&query=$.size.compressedSize&url=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",
  "repository": {
    "url": "git+https://github.com/syntax-tree/estree-util-scope.git",
    "type": "git"
  },
  "bugs": {
    "url": "https://github.com/syntax-tree/estree-util-scope/issues"
  },
  "license": "MIT",
  "versions": {
    "1.0.0": {
      "name": "estree-util-scope",
      "version": "1.0.0",
      "keywords": [
        "ast",
        "ecmascript",
        "estree",
        "javascript",
        "scope",
        "tree"
      ],
      "author": {
        "url": "https://wooorm.com",
        "name": "Titus Wormer",
        "email": "tituswormer@gmail.com"
      },
      "license": "MIT",
      "_id": "estree-util-scope@1.0.0",
      "maintainers": [
        {
          "name": "wooorm",
          "email": "tituswormer@gmail.com"
        }
      ],
      "contributors": [
        {
          "url": "https://wooorm.com",
          "name": "Titus Wormer",
          "email": "tituswormer@gmail.com"
        }
      ],
      "homepage": "https://github.com/syntax-tree/estree-util-scope#readme",
      "bugs": {
        "url": "https://github.com/syntax-tree/estree-util-scope/issues"
      },
      "xo": {
        "rules": {
          "complexity": "off",
          "unicorn/prefer-switch": "off"
        },
        "prettier": true,
        "overrides": [
          {
            "files": [
              "**/*.d.ts"
            ],
            "rules": {
              "@typescript-eslint/ban-types": [
                "error",
                {
                  "extendDefaults": true
                }
              ],
              "@typescript-eslint/array-type": [
                "error",
                {
                  "default": "generic"
                }
              ],
              "@typescript-eslint/consistent-type-definitions": [
                "error",
                "interface"
              ]
            }
          }
        ]
      },
      "dist": {
        "shasum": "9cbdfc77f5cb51e3d9ed4ad9c4adbff22d43e585",
        "tarball": "https://archive.ito.gov.ir/npm/_packages/estree-util-scope/-/estree-util-scope-1.0.0.tgz",
        "fileCount": 10,
        "integrity": "sha512-2CAASclonf+JFWBNJPndcOpA8EMJwa0Q8LUFJEKqXLW6+qBvbFZuF5gItbQOs/umBUkjviCSDCbBwU2cXbmrhQ==",
        "signatures": [
          {
            "sig": "MEUCIDkZZlsJgXrDwLTlOhoQ5lgkpJetc/m1+MczoPWSKinzAiEAtyXmcIlGo9vwRIC2fHWqFMs+7fJ+9TA8bh+LZ8ReICU=",
            "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
          }
        ],
        "unpackedSize": 16536
      },
      "type": "module",
      "types": "./index.d.ts",
      "exports": "./index.js",
      "funding": {
        "url": "https://opencollective.com/unified",
        "type": "opencollective"
      },
      "gitHead": "32dae2048cea45545ea3d54525a3283135b8260b",
      "scripts": {
        "test": "npm run build && npm run format && npm run test-coverage",
        "build": "tsc --build --clean && tsc --build && type-coverage",
        "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
        "prepack": "npm run build && npm run format",
        "test-api": "node --conditions development test.js",
        "test-coverage": "c8 --100 --reporter lcov npm run test-api"
      },
      "_npmUser": {
        "name": "wooorm",
        "email": "tituswormer@gmail.com"
      },
      "prettier": {
        "semi": false,
        "useTabs": false,
        "tabWidth": 2,
        "singleQuote": true,
        "trailingComma": "none",
        "bracketSpacing": false
      },
      "repository": {
        "url": "git+https://github.com/syntax-tree/estree-util-scope.git",
        "type": "git"
      },
      "_npmVersion": "10.8.2",
      "description": "Check what’s defined in an estree scope",
      "directories": {},
      "sideEffects": false,
      "_nodeVersion": "22.7.0",
      "dependencies": {
        "devlop": "^1.0.0",
        "@types/estree": "^1.0.0"
      },
      "remarkConfig": {
        "plugins": [
          "remark-api",
          "remark-preset-wooorm"
        ]
      },
      "typeCoverage": {
        "detail": true,
        "strict": true,
        "atLeast": 100,
        "ignoreCatch": true
      },
      "_hasShrinkwrap": false,
      "devDependencies": {
        "c8": "^10.0.0",
        "xo": "^0.59.0",
        "acorn": "^8.0.0",
        "prettier": "^3.0.0",
        "remark-api": "^1.1.0",
        "remark-cli": "^12.0.0",
        "typescript": "^5.0.0",
        "@types/node": "^22.0.0",
        "estree-walker": "^3.0.0",
        "type-coverage": "^2.0.0",
        "remark-preset-wooorm": "^10.0.0"
      },
      "_npmOperationalInternal": {
        "tmp": "tmp/estree-util-scope_1.0.0_1724943029943_0.042160378709692026",
        "host": "s3://npm-registry-packages"
      }
    }
  },
  "name": "estree-util-scope",
  "time": {
    "created": "2024-08-29T14:50:29.942Z",
    "modified": "2026-06-30T22:22:29.993Z",
    "1.0.0": "2024-08-29T14:50:30.092Z"
  },
  "contributors": [
    {
      "url": "https://wooorm.com",
      "name": "Titus Wormer",
      "email": "tituswormer@gmail.com"
    }
  ],
  "readmeFilename": "readme.md",
  "homepage": "https://github.com/syntax-tree/estree-util-scope#readme"
}