@@ -393,8 +393,8 @@ namespace ts {
393
393
return resolutions ;
394
394
}
395
395
396
- interface DiagnosticCache {
397
- perFile ?: Map < DiagnosticWithLocation [ ] > ;
396
+ interface DiagnosticCache < T extends Diagnostic > {
397
+ perFile ?: Map < T [ ] > ;
398
398
allDiagnostics ?: Diagnostic [ ] ;
399
399
}
400
400
@@ -500,8 +500,8 @@ namespace ts {
500
500
let classifiableNames : UnderscoreEscapedMap < true > ;
501
501
let modifiedFilePaths : Path [ ] | undefined ;
502
502
503
- const cachedSemanticDiagnosticsForFile : DiagnosticCache = { } ;
504
- const cachedDeclarationDiagnosticsForFile : DiagnosticCache = { } ;
503
+ const cachedSemanticDiagnosticsForFile : DiagnosticCache < Diagnostic > = { } ;
504
+ const cachedDeclarationDiagnosticsForFile : DiagnosticCache < DiagnosticWithLocation > = { } ;
505
505
506
506
let resolvedTypeReferenceDirectives = createMap < ResolvedTypeReferenceDirective > ( ) ;
507
507
let fileProcessingDiagnostics = createDiagnosticCollection ( ) ;
@@ -1209,10 +1209,10 @@ namespace ts {
1209
1209
return filesByName . get ( path ) ;
1210
1210
}
1211
1211
1212
- function getDiagnosticsHelper (
1212
+ function getDiagnosticsHelper < T extends Diagnostic > (
1213
1213
sourceFile : SourceFile ,
1214
- getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => ReadonlyArray < DiagnosticWithLocation > ,
1215
- cancellationToken : CancellationToken ) : ReadonlyArray < DiagnosticWithLocation > {
1214
+ getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => ReadonlyArray < T > ,
1215
+ cancellationToken : CancellationToken ) : ReadonlyArray < T > {
1216
1216
if ( sourceFile ) {
1217
1217
return getDiagnostics ( sourceFile , cancellationToken ) ;
1218
1218
}
@@ -1228,7 +1228,7 @@ namespace ts {
1228
1228
return getDiagnosticsHelper ( sourceFile , getSyntacticDiagnosticsForFile , cancellationToken ) ;
1229
1229
}
1230
1230
1231
- function getSemanticDiagnostics ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < DiagnosticWithLocation > {
1231
+ function getSemanticDiagnostics ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < Diagnostic > {
1232
1232
return getDiagnosticsHelper ( sourceFile , getSemanticDiagnosticsForFile , cancellationToken ) ;
1233
1233
}
1234
1234
@@ -1278,11 +1278,11 @@ namespace ts {
1278
1278
}
1279
1279
}
1280
1280
1281
- function getSemanticDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < DiagnosticWithLocation > {
1281
+ function getSemanticDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < Diagnostic > {
1282
1282
return getAndCacheDiagnostics ( sourceFile , cancellationToken , cachedSemanticDiagnosticsForFile , getSemanticDiagnosticsForFileNoCache ) ;
1283
1283
}
1284
1284
1285
- function getSemanticDiagnosticsForFileNoCache ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : DiagnosticWithLocation [ ] {
1285
+ function getSemanticDiagnosticsForFileNoCache ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
1286
1286
return runWithCancellationToken ( ( ) => {
1287
1287
// If skipLibCheck is enabled, skip reporting errors if file is a declaration file.
1288
1288
// If skipDefaultLibCheck is enabled, skip reporting errors if file contains a
@@ -1299,16 +1299,15 @@ namespace ts {
1299
1299
// By default, only type-check .ts, .tsx, and 'External' files (external files are added by plugins)
1300
1300
const includeBindAndCheckDiagnostics = sourceFile . scriptKind === ScriptKind . TS || sourceFile . scriptKind === ScriptKind . TSX ||
1301
1301
sourceFile . scriptKind === ScriptKind . External || isCheckJs ;
1302
- const bindDiagnostics = includeBindAndCheckDiagnostics ? sourceFile . bindDiagnostics : emptyArray ;
1303
- // TODO: GH#18217
1304
- const checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker . getDiagnostics ( sourceFile , cancellationToken ) as ReadonlyArray < DiagnosticWithLocation > : emptyArray ;
1302
+ const bindDiagnostics : ReadonlyArray < Diagnostic > = includeBindAndCheckDiagnostics ? sourceFile . bindDiagnostics : emptyArray ;
1303
+ const checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker . getDiagnostics ( sourceFile , cancellationToken ) : emptyArray ;
1305
1304
const fileProcessingDiagnosticsInFile = fileProcessingDiagnostics . getDiagnostics ( sourceFile . fileName ) ;
1306
1305
const programDiagnosticsInFile = programDiagnostics . getDiagnostics ( sourceFile . fileName ) ;
1307
1306
let diagnostics = bindDiagnostics . concat ( checkDiagnostics , fileProcessingDiagnosticsInFile , programDiagnosticsInFile ) ;
1308
1307
if ( isCheckJs ) {
1309
1308
diagnostics = concatenate ( diagnostics , sourceFile . jsDocDiagnostics ) ;
1310
1309
}
1311
- return filter < DiagnosticWithLocation > ( diagnostics , shouldReportDiagnostic ) ;
1310
+ return filter < Diagnostic > ( diagnostics , shouldReportDiagnostic ) ;
1312
1311
} ) ;
1313
1312
}
1314
1313
@@ -1531,36 +1530,25 @@ namespace ts {
1531
1530
return ts . getDeclarationDiagnostics ( getEmitHost ( noop ) , resolver , sourceFile ) ;
1532
1531
} ) ;
1533
1532
}
1534
- function getAndCacheDiagnostics (
1535
- sourceFile : SourceFile ,
1536
- cancellationToken : CancellationToken ,
1537
- cache : DiagnosticCache ,
1538
- getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => DiagnosticWithLocation [ ]
1539
- ) : ReadonlyArray < DiagnosticWithLocation > ;
1540
- function getAndCacheDiagnostics (
1541
- sourceFile : SourceFile | undefined ,
1542
- cancellationToken : CancellationToken ,
1543
- cache : DiagnosticCache ,
1544
- getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => DiagnosticWithLocation [ ] ,
1545
- ) : ReadonlyArray < Diagnostic > ;
1546
- function getAndCacheDiagnostics (
1533
+
1534
+ function getAndCacheDiagnostics < T extends Diagnostic > (
1547
1535
sourceFile : SourceFile | undefined ,
1548
1536
cancellationToken : CancellationToken ,
1549
- cache : DiagnosticCache ,
1550
- getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => DiagnosticWithLocation [ ] ,
1551
- ) : ReadonlyArray < Diagnostic > {
1537
+ cache : DiagnosticCache < T > ,
1538
+ getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => T [ ] ,
1539
+ ) : ReadonlyArray < T > {
1552
1540
1553
1541
const cachedResult = sourceFile
1554
1542
? cache . perFile && cache . perFile . get ( sourceFile . path )
1555
- : cache . allDiagnostics ;
1543
+ : cache . allDiagnostics as T [ ]
1556
1544
1557
1545
if ( cachedResult ) {
1558
1546
return cachedResult ;
1559
1547
}
1560
1548
const result = getDiagnostics ( sourceFile , cancellationToken ) || emptyArray ;
1561
1549
if ( sourceFile ) {
1562
1550
if ( ! cache . perFile ) {
1563
- cache . perFile = createMap < DiagnosticWithLocation [ ] > ( ) ;
1551
+ cache . perFile = createMap < T [ ] > ( ) ;
1564
1552
}
1565
1553
cache . perFile . set ( sourceFile . path , result ) ;
1566
1554
}
0 commit comments