<h1>eslint-visitor-keys</h1>
<p>Constants and utilities about visitor keys to traverse AST.</p>
<h2>💿 Installation</h2>
<p>Use <a href="https://www.npmjs.com/">npm</a> to install.</p>
<pre><code class="language-bash">$ npm install eslint-visitor-keys
</code></pre>
<h3>Requirements</h3>
<ul>
<li><a href="https://nodejs.org/">Node.js</a> <code>^12.22.0</code>, <code>^14.17.0</code>, or <code>>=16.0.0</code></li>
</ul>
<h2>📖 Usage</h2>
<p>To use in an ESM file:</p>
<pre><code class="language-js">import * as evk from "eslint-visitor-keys"
</code></pre>
<p>To use in a CommonJS file:</p>
<pre><code class="language-js">const evk = require("eslint-visitor-keys")
</code></pre>
<h3>evk.KEYS</h3>
<blockquote>
<p>type: <code>{ [type: string]: string[] | undefined }</code></p>
</blockquote>
<p>Visitor keys. This keys are frozen.</p>
<p>This is an object. Keys are the type of <a href="https://github.com/estree/estree">ESTree</a> nodes. Their values are an array of property names which have child nodes.</p>
<p>For example:</p>
<pre><code>console.log(evk.KEYS.AssignmentExpression) // → ["left", "right"]
</code></pre>
<h3>evk.getKeys(node)</h3>
<blockquote>
<p>type: <code>(node: object) => string[]</code></p>
</blockquote>
<p>Get the visitor keys of a given AST node.</p>
<p>This is similar to <code>Object.keys(node)</code> of ES Standard, but some keys are excluded: <code>parent</code>, <code>leadingComments</code>, <code>trailingComments</code>, and names which start with <code>_</code>.</p>
<p>This will be used to traverse unknown nodes.</p>
<p>For example:</p>
<pre><code class="language-js">const node = {
type: "AssignmentExpression",
left: { type: "Identifier", name: "foo" },
right: { type: "Literal", value: 0 }
}
console.log(evk.getKeys(node)) // → ["type", "left", "right"]
</code></pre>
<h3>evk.unionWith(additionalKeys)</h3>
<blockquote>
<p>type: <code>(additionalKeys: object) => { [type: string]: string[] | undefined }</code></p>
</blockquote>
<p>Make the union set with <code>evk.KEYS</code> and the given keys.</p>
<ul>
<li>The order of keys is, <code>additionalKeys</code> is at first, then <code>evk.KEYS</code> is concatenated after that.</li>
<li>It removes duplicated keys as keeping the first one.</li>
</ul>
<p>For example:</p>
<pre><code class="language-js">console.log(evk.unionWith({
MethodDefinition: ["decorators"]
})) // → { ..., MethodDefinition: ["decorators", "key", "value"], ... }
</code></pre>
<h2>📰 Change log</h2>
<p>See <a href="https://github.com/eslint/eslint-visitor-keys/releases">GitHub releases</a>.</p>
<h2>🍻 Contributing</h2>
<p>Welcome. See <a href="https://eslint.org/docs/developer-guide/contributing/">ESLint contribution guidelines</a>.</p>
<h3>Development commands</h3>
<ul>
<li><code>npm test</code> runs tests and measures code coverage.</li>
<li><code>npm run lint</code> checks source codes with ESLint.</li>
<li><code>npm run coverage</code> opens the code coverage report of the previous test with your default browser.</li>
<li><code>npm run release</code> publishes this package to <a href="https://www.npmjs.com/">npm</a> registory.</li>
</ul>
|