Type definitions for the TypeScript-ESTree AST specification, including parser options and AST node 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.
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;
}Tokens representing literal values in the source code:
true, falsenull42, 3.14, 0x1F)"hello", 'world', `template`)/pattern/flags)`hello ${name}`)Tokens representing names and identifiers:
variable, functionName)<div>, className)#privateField)function, class, interface);, {, }, +, =>)Tokens representing comments in the source code:
/* comment */)// 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