File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,10 +11,25 @@ const options = {
1111const files = [
1212 'sandbox/do-simple-math.ts'
1313] ;
14+
1415const host = ts . createCompilerHost ( options ) ;
1516const 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
1934llvm . initializeAllTargetInfos ( ) ;
2035llvm . initializeAllTargets ( ) ;
You can’t perform that action at this time.
0 commit comments