Security News
Python Overtakes JavaScript as Top Programming Language on GitHub
Python becomes GitHub's top language in 2024, driven by AI and data science projects, while AI-powered security tools are gaining adoption.
@typescript-eslint/visitor-keys
Advanced tools
Visitor keys used to help traverse the TypeScript-ESTree AST
The @typescript-eslint/visitor-keys package provides an enumeration of TypeScript ESTree AST node types and their respective visitor keys. It is primarily used in the context of ESLint plugins and custom rules development to traverse the AST (Abstract Syntax Tree) of TypeScript code and analyze or manipulate the code structure.
AST Node Traversal
This code demonstrates how to use the visitor keys from the package to traverse an AST node and its children recursively. The `traverseAST` function takes a node and a visitor object that contains methods corresponding to node types. It uses the visitor keys to determine which properties of a node to traverse.
const visitorKeys = require('@typescript-eslint/visitor-keys');
function traverseAST(node, visitor) {
if (visitor[node.type]) {
visitor[node.type](node);
}
const keys = visitorKeys[node.type] || [];
keys.forEach((key) => {
const value = node[key];
if (Array.isArray(value)) {
value.forEach(child => traverseAST(child, visitor));
} else if (value && typeof value === 'object') {
traverseAST(value, visitor);
}
});
}
This package provides a list of visitor keys for traversing the AST of JavaScript code. It is similar to @typescript-eslint/visitor-keys but is tailored for JavaScript rather than TypeScript. It is used by ESLint to work with its own rules and plugins.
While not a direct equivalent, babel-types is part of the Babel ecosystem and provides definitions for various AST node types, builders, and assertion methods. It can be used to traverse and manipulate ASTs for both JavaScript and TypeScript, offering a broader scope compared to @typescript-eslint/visitor-keys.
Estraverse is a simple and flexible library for traversing and replacing nodes in an ECMAScript AST. It is not TypeScript-specific but can be used with JavaScript ASTs. It provides a similar traversal functionality but does not rely on a predefined set of visitor keys.
@typescript-eslint/visitor-keys
Visitor keys used to help traverse the TypeScript-ESTree AST.
This is an internal package to the typescript-eslint monorepo. You likely don't want to use it directly.
š See https://typescript-eslint.io for docs on typescript-eslint.
6.3.0 (2023-08-07)
allowTypeImports
enabled (#7379) (cc9a46d)ignorePrimitives
option to be true
(#7331) (dfcafae)You can read about our versioning strategy and releases on our website.
FAQs
Visitor keys used to help traverse the TypeScript-ESTree AST
The npm package @typescript-eslint/visitor-keys receives a total of 52,590,445 weekly downloads. As such, @typescript-eslint/visitor-keys popularity was classified as popular.
We found that @typescript-eslint/visitor-keys demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Ā It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Python becomes GitHub's top language in 2024, driven by AI and data science projects, while AI-powered security tools are gaining adoption.
Security News
Dutch National Police and FBI dismantle Redline and Meta infostealer malware-as-a-service operations in Operation Magnus, seizing servers and source code.
Research
Security News
Socket is tracking a new trend where malicious actors are now exploiting the popularity of LLM research to spread malware through seemingly useful open source packages.