@@ -9,6 +9,13 @@ import { Diagnostic, Diagnostics, Program } from '@angular/compiler-cli';
99import * as ts from 'typescript' ;
1010import { time , timeEnd } from './benchmark' ;
1111
12+ export enum DiagnosticMode {
13+ Syntactic = 1 << 0 ,
14+ Semantic = 1 << 1 ,
15+
16+ All = Syntactic | Semantic ,
17+ Default = All ,
18+ }
1219
1320export class CancellationToken implements ts . CancellationToken {
1421 private _isCancelled = false ;
@@ -36,6 +43,7 @@ export function gatherDiagnostics(
3643 program : ts . Program | Program ,
3744 jitMode : boolean ,
3845 benchmarkLabel : string ,
46+ mode = DiagnosticMode . All ,
3947 cancellationToken ?: CancellationToken ,
4048) : Diagnostics {
4149 const allDiagnostics : Array < ts . Diagnostic | Diagnostic > = [ ] ;
@@ -52,34 +60,44 @@ export function gatherDiagnostics(
5260 }
5361 }
5462
63+ const gatherSyntacticDiagnostics = ( mode & DiagnosticMode . Syntactic ) != 0 ;
64+ const gatherSemanticDiagnostics = ( mode & DiagnosticMode . Semantic ) != 0 ;
65+
5566 if ( jitMode ) {
5667 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+ }
6681 } else {
6782 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+ }
6889
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` ) ;
7895
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+ }
83101 }
84102
85103 return allDiagnostics ;
0 commit comments