@@ -9,6 +9,13 @@ import { Diagnostic, Diagnostics, Program } from '@angular/compiler-cli';
9
9
import * as ts from 'typescript' ;
10
10
import { time , timeEnd } from './benchmark' ;
11
11
12
+ export enum DiagnosticMode {
13
+ Syntactic = 1 << 0 ,
14
+ Semantic = 1 << 1 ,
15
+
16
+ All = Syntactic | Semantic ,
17
+ Default = All ,
18
+ }
12
19
13
20
export class CancellationToken implements ts . CancellationToken {
14
21
private _isCancelled = false ;
@@ -36,6 +43,7 @@ export function gatherDiagnostics(
36
43
program : ts . Program | Program ,
37
44
jitMode : boolean ,
38
45
benchmarkLabel : string ,
46
+ mode = DiagnosticMode . All ,
39
47
cancellationToken ?: CancellationToken ,
40
48
) : Diagnostics {
41
49
const allDiagnostics : Array < ts . Diagnostic | Diagnostic > = [ ] ;
@@ -52,34 +60,44 @@ export function gatherDiagnostics(
52
60
}
53
61
}
54
62
63
+ const gatherSyntacticDiagnostics = ( mode & DiagnosticMode . Syntactic ) != 0 ;
64
+ const gatherSemanticDiagnostics = ( mode & DiagnosticMode . Semantic ) != 0 ;
65
+
55
66
if ( jitMode ) {
56
67
const tsProgram = program as ts . Program ;
57
- // Check syntactic diagnostics.
58
- time ( `${ benchmarkLabel } .gatherDiagnostics.ts.getSyntacticDiagnostics` ) ;
59
- checkDiagnostics ( tsProgram . getSyntacticDiagnostics . bind ( tsProgram ) ) ;
60
- timeEnd ( `${ benchmarkLabel } .gatherDiagnostics.ts.getSyntacticDiagnostics` ) ;
61
-
62
- // Check semantic diagnostics.
63
- time ( `${ benchmarkLabel } .gatherDiagnostics.ts.getSemanticDiagnostics` ) ;
64
- checkDiagnostics ( tsProgram . getSemanticDiagnostics . bind ( tsProgram ) ) ;
65
- timeEnd ( `${ benchmarkLabel } .gatherDiagnostics.ts.getSemanticDiagnostics` ) ;
68
+ if ( gatherSyntacticDiagnostics ) {
69
+ // Check syntactic diagnostics.
70
+ time ( `${ benchmarkLabel } .gatherDiagnostics.ts.getSyntacticDiagnostics` ) ;
71
+ checkDiagnostics ( tsProgram . getSyntacticDiagnostics . bind ( tsProgram ) ) ;
72
+ timeEnd ( `${ benchmarkLabel } .gatherDiagnostics.ts.getSyntacticDiagnostics` ) ;
73
+ }
74
+
75
+ if ( gatherSemanticDiagnostics ) {
76
+ // Check semantic diagnostics.
77
+ time ( `${ benchmarkLabel } .gatherDiagnostics.ts.getSemanticDiagnostics` ) ;
78
+ checkDiagnostics ( tsProgram . getSemanticDiagnostics . bind ( tsProgram ) ) ;
79
+ timeEnd ( `${ benchmarkLabel } .gatherDiagnostics.ts.getSemanticDiagnostics` ) ;
80
+ }
66
81
} else {
67
82
const angularProgram = program as Program ;
83
+ if ( gatherSyntacticDiagnostics ) {
84
+ // Check TypeScript syntactic diagnostics.
85
+ time ( `${ benchmarkLabel } .gatherDiagnostics.ng.getTsSyntacticDiagnostics` ) ;
86
+ checkDiagnostics ( angularProgram . getTsSyntacticDiagnostics . bind ( angularProgram ) ) ;
87
+ timeEnd ( `${ benchmarkLabel } .gatherDiagnostics.ng.getTsSyntacticDiagnostics` ) ;
88
+ }
68
89
69
- // Check TypeScript syntactic diagnostics.
70
- time ( `${ benchmarkLabel } .gatherDiagnostics.ng.getTsSyntacticDiagnostics` ) ;
71
- checkDiagnostics ( angularProgram . getTsSyntacticDiagnostics . bind ( angularProgram ) ) ;
72
- timeEnd ( `${ benchmarkLabel } .gatherDiagnostics.ng.getTsSyntacticDiagnostics` ) ;
73
-
74
- // Check TypeScript semantic and Angular structure diagnostics.
75
- time ( `${ benchmarkLabel } .gatherDiagnostics.ng.getTsSemanticDiagnostics` ) ;
76
- checkDiagnostics ( angularProgram . getTsSemanticDiagnostics . bind ( angularProgram ) ) ;
77
- timeEnd ( `${ benchmarkLabel } .gatherDiagnostics.ng.getTsSemanticDiagnostics` ) ;
90
+ if ( gatherSemanticDiagnostics ) {
91
+ // Check TypeScript semantic and Angular structure diagnostics.
92
+ time ( `${ benchmarkLabel } .gatherDiagnostics.ng.getTsSemanticDiagnostics` ) ;
93
+ checkDiagnostics ( angularProgram . getTsSemanticDiagnostics . bind ( angularProgram ) ) ;
94
+ timeEnd ( `${ benchmarkLabel } .gatherDiagnostics.ng.getTsSemanticDiagnostics` ) ;
78
95
79
- // Check Angular semantic diagnostics
80
- time ( `${ benchmarkLabel } .gatherDiagnostics.ng.getNgSemanticDiagnostics` ) ;
81
- checkDiagnostics ( angularProgram . getNgSemanticDiagnostics . bind ( angularProgram ) ) ;
82
- timeEnd ( `${ benchmarkLabel } .gatherDiagnostics.ng.getNgSemanticDiagnostics` ) ;
96
+ // Check Angular semantic diagnostics
97
+ time ( `${ benchmarkLabel } .gatherDiagnostics.ng.getNgSemanticDiagnostics` ) ;
98
+ checkDiagnostics ( angularProgram . getNgSemanticDiagnostics . bind ( angularProgram ) ) ;
99
+ timeEnd ( `${ benchmarkLabel } .gatherDiagnostics.ng.getNgSemanticDiagnostics` ) ;
100
+ }
83
101
}
84
102
85
103
return allDiagnostics ;
0 commit comments