CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-typescript-eslint--types

Type definitions for the TypeScript-ESTree AST specification, including parser options and AST node types

Pending
Overview
Eval results
Files

token-types.mddocs/

Token Types

Enumeration of lexical token types for parsing and syntax highlighting in the TypeScript-ESTree ecosystem. These constants enable type-safe token classification and processing.

Capabilities

AST_TOKEN_TYPES Enum

Complete enumeration of all token types recognized by the TypeScript parser.

enum AST_TOKEN_TYPES {
  // Literal tokens
  Boolean = 'Boolean',
  Null = 'Null',
  Numeric = 'Numeric',
  String = 'String',
  RegularExpression = 'RegularExpression',
  Template = 'Template',
  
  // Identifier tokens
  Identifier = 'Identifier',
  JSXIdentifier = 'JSXIdentifier',
  PrivateIdentifier = 'PrivateIdentifier',
  
  // Special tokens
  JSXText = 'JSXText',
  Keyword = 'Keyword',
  Punctuator = 'Punctuator',
  
  // Comment tokens
  Block = 'Block',
  Line = 'Line',
}

Usage Examples:

import { AST_TOKEN_TYPES } from "@typescript-eslint/types";

// Token classification
function classifyToken(token: Token): string {
  switch (token.type) {
    case AST_TOKEN_TYPES.Identifier:
      return `Identifier: ${token.value}`;
    
    case AST_TOKEN_TYPES.Keyword:
      return `Keyword: ${token.value}`;
    
    case AST_TOKEN_TYPES.String:
      return `String literal: ${token.value}`;
    
    case AST_TOKEN_TYPES.Numeric:
      return `Number: ${token.value}`;
    
    case AST_TOKEN_TYPES.Boolean:
      return `Boolean: ${token.value}`;
    
    case AST_TOKEN_TYPES.Block:
    case AST_TOKEN_TYPES.Line:
      return `Comment: ${token.value}`;
    
    default:
      return `Other token: ${token.type}`;
  }
}

// Filter tokens by category
function isLiteralToken(tokenType: AST_TOKEN_TYPES): boolean {
  return [
    AST_TOKEN_TYPES.Boolean,
    AST_TOKEN_TYPES.Null,
    AST_TOKEN_TYPES.Numeric,
    AST_TOKEN_TYPES.String,
    AST_TOKEN_TYPES.RegularExpression,
    AST_TOKEN_TYPES.Template,
  ].includes(tokenType);
}

function isCommentToken(tokenType: AST_TOKEN_TYPES): boolean {
  return tokenType === AST_TOKEN_TYPES.Block || tokenType === AST_TOKEN_TYPES.Line;
}

Token Categories

Literal Tokens

Tokens representing literal values in the source code:

  • Boolean: true, false
  • Null: null
  • Numeric: Integer and floating-point numbers (42, 3.14, 0x1F)
  • String: String literals ("hello", 'world', `template`)
  • RegularExpression: Regular expression literals (/pattern/flags)
  • Template: Template literal parts (`hello ${name}`)

Identifier Tokens

Tokens representing names and identifiers:

  • Identifier: Standard JavaScript identifiers (variable, functionName)
  • JSXIdentifier: JSX element and attribute names (<div>, className)
  • PrivateIdentifier: Private class field names (#privateField)

Special Tokens

  • JSXText: Text content within JSX elements
  • Keyword: Reserved JavaScript/TypeScript keywords (function, class, interface)
  • Punctuator: Operators and punctuation (;, {, }, +, =>)

Comment Tokens

Tokens representing comments in the source code:

  • Block: Multi-line comments (/* comment */)
  • Line: Single-line comments (// comment)

Usage in Syntax Highlighting:

import { AST_TOKEN_TYPES } from "@typescript-eslint/types";

function getTokenStyle(tokenType: AST_TOKEN_TYPES): string {
  switch (tokenType) {
    case AST_TOKEN_TYPES.Keyword:
      return 'keyword';
    
    case AST_TOKEN_TYPES.String:
    case AST_TOKEN_TYPES.Template:
      return 'string';
    
    case AST_TOKEN_TYPES.Numeric:
    case AST_TOKEN_TYPES.Boolean:
    case AST_TOKEN_TYPES.Null:
      return 'literal';
    
    case AST_TOKEN_TYPES.Block:
    case AST_TOKEN_TYPES.Line:
      return 'comment';
    
    case AST_TOKEN_TYPES.Identifier:
      return 'identifier';
    
    case AST_TOKEN_TYPES.RegularExpression:
      return 'regex';
    
    default:
      return 'default';
  }
}

Install with Tessl CLI

npx tessl i tessl/npm-typescript-eslint--types

docs

ast-node-types.md

index.md

parser-configuration.md

token-types.md

typescript-estree.md

typescript-libraries.md

tile.json