https://github.com/eslint/eslint-visitor-keys
Constants and utilities about visitor keys to traverse AST.
https://github.com/eslint/eslint-visitor-keys
Last synced: 5 months ago
JSON representation
Constants and utilities about visitor keys to traverse AST.
- Host: GitHub
- URL: https://github.com/eslint/eslint-visitor-keys
- Owner: eslint
- License: apache-2.0
- Created: 2017-09-24T08:41:43.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2024-03-05T16:39:17.000Z (over 1 year ago)
- Last Synced: 2024-04-14T07:44:23.650Z (about 1 year ago)
- Language: JavaScript
- Size: 88.9 KB
- Stars: 40
- Watchers: 16
- Forks: 18
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# eslint-visitor-keys
[](https://www.npmjs.com/package/eslint-visitor-keys)
[](http://www.npmtrends.com/eslint-visitor-keys)
[](https://github.com/eslint/eslint-visitor-keys/actions)> [!Important]
> Active development for this project has moved to https://github.com/eslint/js. Please open issues/PRs there.Constants and utilities about visitor keys to traverse AST.
## 💿 Installation
Use [npm] to install.
```bash
$ npm install eslint-visitor-keys
```### Requirements
- [Node.js] `^18.18.0`, `^20.9.0`, or `>=21.1.0`
## 📖 Usage
To use in an ESM file:
```js
import * as evk from "eslint-visitor-keys"
```To use in a CommonJS file:
```js
const evk = require("eslint-visitor-keys")
```### evk.KEYS
> type: `{ [type: string]: string[] | undefined }`
Visitor keys. This keys are frozen.
This is an object. Keys are the type of [ESTree] nodes. Their values are an array of property names which have child nodes.
For example:
```
console.log(evk.KEYS.AssignmentExpression) // → ["left", "right"]
```### evk.getKeys(node)
> type: `(node: object) => string[]`
Get the visitor keys of a given AST node.
This is similar to `Object.keys(node)` of ES Standard, but some keys are excluded: `parent`, `leadingComments`, `trailingComments`, and names which start with `_`.
This will be used to traverse unknown nodes.
For example:
```js
const node = {
type: "AssignmentExpression",
left: { type: "Identifier", name: "foo" },
right: { type: "Literal", value: 0 }
}
console.log(evk.getKeys(node)) // → ["type", "left", "right"]
```### evk.unionWith(additionalKeys)
> type: `(additionalKeys: object) => { [type: string]: string[] | undefined }`
Make the union set with `evk.KEYS` and the given keys.
- The order of keys is, `additionalKeys` is at first, then `evk.KEYS` is concatenated after that.
- It removes duplicated keys as keeping the first one.For example:
```js
console.log(evk.unionWith({
MethodDefinition: ["decorators"]
})) // → { ..., MethodDefinition: ["decorators", "key", "value"], ... }
```## 📰 Change log
See [GitHub releases](https://github.com/eslint/eslint-visitor-keys/releases).
## 🍻 Contributing
Welcome. See [ESLint contribution guidelines](https://eslint.org/docs/developer-guide/contributing/).
### Development commands
- `npm test` runs tests and measures code coverage.
- `npm run lint` checks source codes with ESLint.
- `npm run test:open-coverage` opens the code coverage report of the previous test with your default browser.[npm]: https://www.npmjs.com/
[Node.js]: https://nodejs.org/
[ESTree]: https://github.com/estree/estree