Understanding the abstract syntax tree (AST)

As we have already learned, an abstract syntax tree, or AST, is a tree-like data structure used to represent the abstract syntactic structure of source code written in a programming language. Each node of the AST represents a construct that occurs in the source code.

We are now going to look at a small TypeScript code snippet to understand the AST in detail. There is nothing very special about the following code snippet—it simply declares an interface named Weapon and a couple of classes, named Katana and Ninja. It then creates an instance of the Ninja class and invokes one of its methods:

interface Weapon { tryHit(fromDistance: number): boolean; } class Katana implements Weapon { public tryHit(fromDistance: ...

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.