Accessing module details with ts-simple-ast

The following code snippet demonstrates how we can use the ts-simple-ast APIs to access and manipulate module import and export declarations.

Note that the preceding example is not meant to be executed. It is a showcase of the available methods in the ts-simple-ast API, but it is not an executable demo.

Just like in the preceding examples, we are going to use the getAst and getSourceFiles methods to access the source code's objects:

import chalk from "chalk"; import Ast, { DiagnosticMessageChain } from "ts-simple-ast"; 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.