JavaScript language tools monorepo containing espree parser, eslint-scope analyzer, and eslint-visitor-keys utilities
npx @tessl/cli install tessl/npm-eslint-js@1.0.0ESLint JS is a JavaScript language tools monorepo that provides essential components for static analysis of JavaScript and TypeScript code. It contains three interconnected packages that form a complete JavaScript parsing and scope analysis toolkit used by ESLint and other JavaScript tooling.
npm install espree (JavaScript parser)npm install eslint-scope (Scope analyzer)npm install eslint-visitor-keys (AST visitor utilities)Each package provides its own imports:
// espree - JavaScript parser
import * as espree from "espree";
import { parse, tokenize } from "espree";
// eslint-scope - Scope analyzer
import { analyze } from "eslint-scope";
// eslint-visitor-keys - AST visitor utilities
import { getKeys, unionWith, KEYS } from "eslint-visitor-keys";For CommonJS:
const espree = require("espree");
const { analyze } = require("eslint-scope");
const { getKeys, KEYS } = require("eslint-visitor-keys");import * as espree from "espree";
import { analyze } from "eslint-scope";
import { getKeys } from "eslint-visitor-keys";
// Parse JavaScript code into AST
const ast = espree.parse('let foo = "bar"; function test() { return foo; }', {
ecmaVersion: 2022,
sourceType: "module"
});
// Analyze scope and variable usage
const scopeManager = analyze(ast, { ecmaVersion: 2022, sourceType: "module" });
// Get visitor keys for AST traversal
const keys = getKeys(ast); // ["type", "body", "sourceType"]The ESLint JS toolkit is built around three core components that work together:
These packages form the foundation for JavaScript static analysis, enabling tools like ESLint to understand code structure, variable usage, and scope relationships.
Core parsing functionality that converts JavaScript source code into Abstract Syntax Trees with full ECMAScript support.
/**
* Parses JavaScript code and returns an Abstract Syntax Tree (AST)
* @param {string} code - The JavaScript code to parse
* @param {ParserOptions} options - Parser configuration options
* @returns {Program} The "Program" AST node
*/
function parse(code, options);
/**
* Tokenizes JavaScript code and returns an array of tokens
* @param {string} code - The JavaScript code to tokenize
* @param {ParserOptions} options - Parser configuration options
* @returns {Token[]} Array of token objects
*/
function tokenize(code, options);Analyzes JavaScript AST to identify variable scopes, references, and declarations for static analysis tools.
/**
* Analyzes AST and returns scope information
* @param {espree.Tree} tree - AST from espree.parse()
* @param {AnalysisOptions} options - Analysis configuration options
* @returns {ScopeManager} Scope manager with all scopes and references
*/
function analyze(tree, options);
interface ScopeManager {
scopes: Scope[];
globalScope: Scope;
acquire(node: espree.Node, inner?: boolean): Scope | null;
getDeclaredVariables(node: espree.Node): Variable[];
}Provides metadata about AST node types and their child properties for AST traversal and analysis.
/**
* Get visitor keys for an AST node
* @param {Object} node - AST node
* @returns {readonly string[]} Array of property names that contain child nodes
*/
function getKeys(node);
/**
* Merge additional keys with default visitor keys
* @param {VisitorKeys} additionalKeys - Additional visitor key mappings
* @returns {VisitorKeys} Combined visitor keys
*/
function unionWith(additionalKeys);
/** Complete mapping of AST node types to their child node keys */
const KEYS: VisitorKeys;