or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

ast-utilities.mdconfiguration.mdindex.mdparsing.mdprogram-management.mdtype-system.md
tile.json

tessl/npm-typescript-eslint--typescript-estree

A parser that converts TypeScript source code into an ESTree compatible form

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@typescript-eslint/typescript-estree@8.42.x

To install, run

npx @tessl/cli install tessl/npm-typescript-eslint--typescript-estree@8.42.0

index.mddocs/

TypeScript ESTree

TypeScript ESTree is a parser that converts TypeScript source code into an ESTree-compatible Abstract Syntax Tree (AST) format. It serves as a crucial bridge between TypeScript's native compiler API and the ESTree AST specification used by JavaScript tooling ecosystems like ESLint. The parser handles TypeScript-specific syntax features including type annotations, interfaces, generics, decorators, and advanced TypeScript constructs while maintaining compatibility with ESLint's plugin architecture.

Package Information

  • Package Name: @typescript-eslint/typescript-estree
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @typescript-eslint/typescript-estree

Core Imports

import { parse, parseAndGenerateServices } from "@typescript-eslint/typescript-estree";
import type { TSESTreeOptions, ParserServices } from "@typescript-eslint/typescript-estree";

For CommonJS:

const { parse, parseAndGenerateServices } = require("@typescript-eslint/typescript-estree");

Basic Usage

import { parse, parseAndGenerateServices } from "@typescript-eslint/typescript-estree";

// Simple parsing without type information
const code = `const x: number = 42;`;
const ast = parse(code, {
  loc: true,
  range: true
});

// Full parsing with TypeScript services
const result = parseAndGenerateServices(code, {
  loc: true,
  range: true,
  project: "./tsconfig.json"
});

console.log(result.ast.type); // "Program"
console.log(result.services.program !== null); // true if project provided

Architecture

TypeScript ESTree is built around several key components:

  • Parser Functions: Core parsing functions (parse, parseAndGenerateServices) for different use cases
  • TypeScript Program Management: Sophisticated caching and program creation for performance
  • AST Conversion: Conversion layer from TypeScript AST to ESTree-compatible format
  • Parser Services: Optional type information services when working with TypeScript projects
  • Utility Functions: Helper functions for AST traversal, node inspection, and version compatibility
  • Cache Management: Comprehensive caching system for programs, configurations, and parsing results

Capabilities

Core Parsing

Primary parsing functions that convert TypeScript source code into ESTree-compatible AST format.

function parse<T extends TSESTreeOptions = TSESTreeOptions>(
  code: string,
  options?: T
): AST<T>;

function parseAndGenerateServices<T extends TSESTreeOptions = TSESTreeOptions>(
  code: string | ts.SourceFile,
  options: T
): ParseAndGenerateServicesResult<T>;

Core Parsing

Parser Configuration

Configuration options and services for controlling parsing behavior and accessing TypeScript type information.

interface TSESTreeOptions {
  loc?: boolean;
  range?: boolean;
  tokens?: boolean;
  comment?: boolean;
  project?: boolean | string | string[] | null;
  projectService?: boolean | ProjectServiceOptions;
  filePath?: string;
  jsx?: boolean;
  // ... additional options
}

interface ParserServices {
  program: ts.Program | null;
  esTreeNodeToTSNodeMap: ParserWeakMapESTreeToTSNode;
  tsNodeToESTreeNodeMap: ParserWeakMap<TSNode | TSToken, TSESTree.Node>;
  // ... additional services when program available
}

Parser Configuration

TypeScript Program Management

Functions for creating and managing TypeScript programs with sophisticated caching.

function createProgram(configFile: string): ts.Program;
function getCanonicalFileName(fileName: string): string;
function clearCaches(): void;

Program Management

AST Utilities

Utility functions for working with TypeScript and ESTree AST nodes.

function simpleTraverse(
  startingNode: TSESTree.Node,
  options: SimpleTraverseOptions,
  setParentPointers?: boolean
): void;

function getModifiers(
  node: ts.Node | null | undefined,
  includeIllegalModifiers?: boolean
): ts.Modifier[] | undefined;

function getScriptKind(filePath: string, jsx: boolean): ts.ScriptKind;

AST Utilities

Type System Integration

Types and interfaces for working with ESTree-compatible TypeScript AST nodes and TypeScript integration.

type AST<T extends TSESTreeOptions> = 
  (T['comment'] extends true ? { comments: TSESTree.Comment[] } : {}) &
  (T['tokens'] extends true ? { tokens: TSESTree.Token[] } : {}) &
  TSESTree.Program;

interface ParseAndGenerateServicesResult<T extends TSESTreeOptions> {
  ast: AST<T>;
  services: ParserServices;
}

Type System

Types

// Core result types
type AST<T extends TSESTreeOptions> = 
  (T['comment'] extends true ? { comments: TSESTree.Comment[] } : {}) &
  (T['tokens'] extends true ? { tokens: TSESTree.Token[] } : {}) &
  TSESTree.Program;

interface ParseAndGenerateServicesResult<T extends TSESTreeOptions> {
  ast: AST<T>;
  services: ParserServices;
}

// Parser services union type
type ParserServices = 
  | ParserServicesWithoutTypeInformation
  | ParserServicesWithTypeInformation;

// Error class for parsing errors
class TSError extends Error {
  constructor(
    message: string,
    fileName: string,
    location: {
      start: { line: number; column: number; offset: number };
      end: { line: number; column: number; offset: number };
    }
  );
}

// Version compatibility object
const typescriptVersionIsAtLeast: Record<'4.7' | '4.8' | '4.9' | '5.0' | '5.1' | '5.2' | '5.3' | '5.4', boolean>;