Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@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.
Visitor keys used to help traverse the TypeScript-ESTree AST
4.28.5 (2021-07-26)
Note: Version bump only for package @typescript-eslint/typescript-eslint
FAQs
Visitor keys used to help traverse the TypeScript-ESTree AST
The npm package @typescript-eslint/visitor-keys receives a total of 48,586,780 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.