1
1
import * as ts from 'typescript' ;
2
+ import { CompilationResult , emptyCompilationResult } from './reporter' ;
2
3
3
4
export interface TypeScript14 {
4
5
createSourceFile ( filename : string , content : string , target : ts . ScriptTarget , version : string ) ;
@@ -22,12 +23,12 @@ export interface Program15 {
22
23
getGlobalDiagnostics ( ) : ts . Diagnostic [ ] ;
23
24
getSemanticDiagnostics ( ) : ts . Diagnostic [ ] ;
24
25
getDeclarationDiagnostics ( ) : ts . Diagnostic [ ] ;
25
- emit ( ) : { diagnostics : ts . Diagnostic [ ] ; } ;
26
+ emit ( ) : { diagnostics : ts . Diagnostic [ ] ; emitSkipped : boolean ; } ;
26
27
}
27
28
28
29
export interface TypeChecker14 {
29
30
getDiagnostics ( sourceFile ?: ts . SourceFile ) : ts . Diagnostic [ ] ;
30
- emitFiles ( ) : { diagnostics : ts . Diagnostic [ ] } ;
31
+ emitFiles ( ) : { diagnostics : ts . Diagnostic [ ] ; } ;
31
32
}
32
33
export interface DiagnosticMessageChain15 {
33
34
messageText : string ;
@@ -54,9 +55,13 @@ export function getFileName(thing: { filename: string} | { fileName: string }):
54
55
if ( ( < any > thing ) . filename ) return ( < any > thing ) . filename ; // TS 1.4
55
56
return ( < any > thing ) . fileName ; // TS 1.5
56
57
}
57
- export function getDiagnosticsAndEmit ( program : Program14 | Program15 ) : ts . Diagnostic [ ] {
58
+ export function getDiagnosticsAndEmit ( program : Program14 | Program15 ) : [ ts . Diagnostic [ ] , CompilationResult ] {
59
+ let result = emptyCompilationResult ( ) ;
60
+
58
61
if ( ( < Program14 > program ) . getDiagnostics ) { // TS 1.4
59
62
let errors = ( < Program14 > program ) . getDiagnostics ( ) ;
63
+
64
+ result . syntaxErrors = errors . length ;
60
65
61
66
if ( ! errors . length ) {
62
67
// If there are no syntax errors, check types
@@ -67,21 +72,34 @@ export function getDiagnosticsAndEmit(program: Program14 | Program15): ts.Diagno
67
72
const emitErrors = checker . emitFiles ( ) . diagnostics ;
68
73
69
74
errors = semanticErrors . concat ( emitErrors ) ;
75
+ result . semanticErrors = errors . length ;
76
+ } else {
77
+ result . emitSkipped = true ;
70
78
}
71
79
72
- return errors ;
80
+ return [ errors , result ] ;
73
81
} else { // TS 1.5
74
82
let errors = ( < Program15 > program ) . getSyntacticDiagnostics ( ) ;
75
- if ( errors . length === 0 ) errors = ( < Program15 > program ) . getGlobalDiagnostics ( ) ;
76
-
77
- // Remove error: "File '...' is not under 'rootDir' '...'. 'rootDir' is expected to contain all source files."
78
- // This is handled by ICompiler#correctSourceMap, so this error can be muted.
79
- errors = errors . filter ( ( item ) => item . code !== 6059 ) ;
83
+ result . syntaxErrors = errors . length ;
84
+ if ( errors . length === 0 ) {
85
+ errors = ( < Program15 > program ) . getGlobalDiagnostics ( ) ;
86
+
87
+ // Remove error: "File '...' is not under 'rootDir' '...'. 'rootDir' is expected to contain all source files."
88
+ // This is handled by ICompiler#correctSourceMap, so this error can be muted.
89
+ errors = errors . filter ( ( item ) => item . code !== 6059 ) ;
90
+
91
+ result . globalErrors = errors . length ;
92
+ }
80
93
81
- if ( errors . length === 0 ) errors = ( < Program15 > program ) . getSemanticDiagnostics ( ) ;
94
+ if ( errors . length === 0 ) {
95
+ errors = ( < Program15 > program ) . getSemanticDiagnostics ( ) ;
96
+ result . semanticErrors = errors . length ;
97
+ }
82
98
83
99
const emitOutput = ( < Program15 > program ) . emit ( ) ;
84
- return errors . concat ( emitOutput . diagnostics ) ;
100
+ result . emitErrors = emitOutput . diagnostics . length ;
101
+ result . emitSkipped = emitOutput . emitSkipped ;
102
+ return [ errors . concat ( emitOutput . diagnostics ) , result ] ;
85
103
}
86
104
}
87
105
export function getLineAndCharacterOfPosition ( typescript : typeof ts , file : TSFile14 | TSFile15 , position : number ) {
0 commit comments