0Pricing
TypeScript Academy · Lesson

Traversing the AST with Visitors

Walk syntax tree nodes to analyze code structure.

What Is the AST?

TypeScript parses source code into an Abstract Syntax Tree (AST) — a tree of nodes representing language constructs like variables, functions, and expressions.

import ts from "typescript";
const sf = ts.createSourceFile(
  "example.ts",
  "const x = 1;",
  ts.ScriptTarget.Latest
);

Node Kinds

Every AST node has a kind property (a ts.SyntaxKind enum value) indicating what it represents.

import ts from "typescript";
// Common kinds:
// ts.SyntaxKind.VariableDeclaration
// ts.SyntaxKind.FunctionDeclaration
// ts.SyntaxKind.Identifier

All lessons in this course

  1. Creating a TypeScript Program with the API
  2. Traversing the AST with Visitors
  3. Custom Transformers and Code Generation
  4. Building a Simple Linting Tool
← Back to TypeScript Academy