Traversing the AST with ts-simple-ast

The following code snippet implements an application that is almost identical to the application that we implemented in the preceding section. The most notable difference is that, instead of using the core TypeScript compiler APIs, we are going to use the ts-simple-ast helpers:

import chalk from "chalk"; 
import Ast, { DiagnosticMessageChain } from "ts-simple-ast"; 

The following function is used in many of the examples in this chapter, and it is used to get an instance of the TypeScript AST, given certain files and the desired compiler settings:

function getAst(tsConfigPath: string, sourceFilesPath: string) { const ast = new Ast({ tsConfigFilePath: tsConfigPath, addFilesFromTsConfig: false }); ast.addExistingSourceFiles(sourceFilesPath); ...

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.