April 2018
Beginner
536 pages
13h 21m
English
The following code snippet implements a very small application that uses ts-simple-ast to find errors in a TypeScript file using the error diagnostic APIs. The application uses the chalk npm module to display errors using a red font in the command-line interface:
import chalk from "chalk";
import Ast, { DiagnosticMessageChain } from "ts-simple-ast";
The following function is the same getAst function that we used in the preceding section:
function getAst(tsConfigPath: string, sourceFilesPath: string) {
const ast = new Ast({
tsConfigFilePath: tsConfigPath,
addFilesFromTsConfig: false
});
ast.addExistingSourceFiles(sourceFilesPath);
return ast;
}
The AST provided by ts-simple-ast includes a method named getDiagnostics ...