Skip to content

Commit 3dd2c01

Browse files
committed
Feature: Run TSC diagnostics
1 parent 28a8ad5 commit 3dd2c01

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/cli.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,25 @@ const options = {
1111
const files = [
1212
'sandbox/do-simple-math.ts'
1313
];
14+
1415
const host = ts.createCompilerHost(options);
1516
const program = ts.createProgram(files, options, host);
16-
17-
// console.log(ast);
17+
const diagnostics = ts.getPreEmitDiagnostics(program);
18+
19+
if (diagnostics.length) {
20+
diagnostics.forEach(diagnostic => {
21+
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
22+
if (!diagnostic.file) {
23+
console.log(message);
24+
return;
25+
}
26+
27+
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!);
28+
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
29+
});
30+
31+
process.exit(1);
32+
}
1833

1934
llvm.initializeAllTargetInfos();
2035
llvm.initializeAllTargets();

0 commit comments

Comments
 (0)