@@ -394,7 +394,7 @@ namespace ts {
394
394
}
395
395
396
396
interface DiagnosticCache {
397
- perFile ?: Map < Diagnostic [ ] > ;
397
+ perFile ?: Map < DiagnosticWithLocation [ ] > ;
398
398
allDiagnostics ?: Diagnostic [ ] ;
399
399
}
400
400
@@ -453,7 +453,7 @@ namespace ts {
453
453
454
454
export function getConfigFileParsingDiagnostics ( configFileParseResult : ParsedCommandLine ) : ReadonlyArray < Diagnostic > {
455
455
return configFileParseResult . options . configFile ?
456
- configFileParseResult . options . configFile . parseDiagnostics . concat ( configFileParseResult . errors ) :
456
+ [ ... configFileParseResult . options . configFile . parseDiagnostics , ... configFileParseResult . errors ] :
457
457
configFileParseResult . errors ;
458
458
}
459
459
@@ -1211,8 +1211,8 @@ namespace ts {
1211
1211
1212
1212
function getDiagnosticsHelper (
1213
1213
sourceFile : SourceFile ,
1214
- getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => ReadonlyArray < Diagnostic > ,
1215
- cancellationToken : CancellationToken ) : ReadonlyArray < Diagnostic > {
1214
+ getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => ReadonlyArray < DiagnosticWithLocation > ,
1215
+ cancellationToken : CancellationToken ) : ReadonlyArray < DiagnosticWithLocation > {
1216
1216
if ( sourceFile ) {
1217
1217
return getDiagnostics ( sourceFile , cancellationToken ) ;
1218
1218
}
@@ -1224,15 +1224,15 @@ namespace ts {
1224
1224
} ) ) ;
1225
1225
}
1226
1226
1227
- function getSyntacticDiagnostics ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < Diagnostic > {
1227
+ function getSyntacticDiagnostics ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < DiagnosticWithLocation > {
1228
1228
return getDiagnosticsHelper ( sourceFile , getSyntacticDiagnosticsForFile , cancellationToken ) ;
1229
1229
}
1230
1230
1231
- function getSemanticDiagnostics ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < Diagnostic > {
1231
+ function getSemanticDiagnostics ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < DiagnosticWithLocation > {
1232
1232
return getDiagnosticsHelper ( sourceFile , getSemanticDiagnosticsForFile , cancellationToken ) ;
1233
1233
}
1234
1234
1235
- function getDeclarationDiagnostics ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < Diagnostic > {
1235
+ function getDeclarationDiagnostics ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < DiagnosticWithLocation > {
1236
1236
const options = program . getCompilerOptions ( ) ;
1237
1237
// collect diagnostics from the program only once if either no source file was specified or out/outFile is set (bundled emit)
1238
1238
if ( ! sourceFile || options . out || options . outFile ) {
@@ -1243,7 +1243,7 @@ namespace ts {
1243
1243
}
1244
1244
}
1245
1245
1246
- function getSyntacticDiagnosticsForFile ( sourceFile : SourceFile ) : ReadonlyArray < Diagnostic > {
1246
+ function getSyntacticDiagnosticsForFile ( sourceFile : SourceFile ) : ReadonlyArray < DiagnosticWithLocation > {
1247
1247
// For JavaScript files, we report semantic errors for using TypeScript-only
1248
1248
// constructs from within a JavaScript file as syntactic errors.
1249
1249
if ( isSourceFileJavaScript ( sourceFile ) ) {
@@ -1278,11 +1278,11 @@ namespace ts {
1278
1278
}
1279
1279
}
1280
1280
1281
- function getSemanticDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
1281
+ function getSemanticDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < DiagnosticWithLocation > {
1282
1282
return getAndCacheDiagnostics ( sourceFile , cancellationToken , cachedSemanticDiagnosticsForFile , getSemanticDiagnosticsForFileNoCache ) ;
1283
1283
}
1284
1284
1285
- function getSemanticDiagnosticsForFileNoCache ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
1285
+ function getSemanticDiagnosticsForFileNoCache ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : DiagnosticWithLocation [ ] {
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
@@ -1300,14 +1300,15 @@ namespace ts {
1300
1300
const includeBindAndCheckDiagnostics = sourceFile . scriptKind === ScriptKind . TS || sourceFile . scriptKind === ScriptKind . TSX ||
1301
1301
sourceFile . scriptKind === ScriptKind . External || isCheckJs ;
1302
1302
const bindDiagnostics = includeBindAndCheckDiagnostics ? sourceFile . bindDiagnostics : emptyArray ;
1303
- const checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker . getDiagnostics ( sourceFile , cancellationToken ) : emptyArray ;
1303
+ // TODO: GH#18217
1304
+ const checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker . getDiagnostics ( sourceFile , cancellationToken ) as ReadonlyArray < DiagnosticWithLocation > : emptyArray ;
1304
1305
const fileProcessingDiagnosticsInFile = fileProcessingDiagnostics . getDiagnostics ( sourceFile . fileName ) ;
1305
1306
const programDiagnosticsInFile = programDiagnostics . getDiagnostics ( sourceFile . fileName ) ;
1306
1307
let diagnostics = bindDiagnostics . concat ( checkDiagnostics , fileProcessingDiagnosticsInFile , programDiagnosticsInFile ) ;
1307
1308
if ( isCheckJs ) {
1308
1309
diagnostics = concatenate ( diagnostics , sourceFile . jsDocDiagnostics ) ;
1309
1310
}
1310
- return filter ( diagnostics , shouldReportDiagnostic ) ;
1311
+ return filter < DiagnosticWithLocation > ( diagnostics , shouldReportDiagnostic ) ;
1311
1312
} ) ;
1312
1313
}
1313
1314
@@ -1336,9 +1337,9 @@ namespace ts {
1336
1337
return true ;
1337
1338
}
1338
1339
1339
- function getJavaScriptSyntacticDiagnosticsForFile ( sourceFile : SourceFile ) : Diagnostic [ ] {
1340
+ function getJavaScriptSyntacticDiagnosticsForFile ( sourceFile : SourceFile ) : DiagnosticWithLocation [ ] {
1340
1341
return runWithCancellationToken ( ( ) => {
1341
- const diagnostics : Diagnostic [ ] = [ ] ;
1342
+ const diagnostics : DiagnosticWithLocation [ ] = [ ] ;
1342
1343
let parent : Node = sourceFile ;
1343
1344
walk ( sourceFile ) ;
1344
1345
@@ -1506,20 +1507,20 @@ namespace ts {
1506
1507
}
1507
1508
}
1508
1509
1509
- function createDiagnosticForNodeArray ( nodes : NodeArray < Node > , message : DiagnosticMessage , arg0 ?: string | number , arg1 ?: string | number , arg2 ?: string | number ) : Diagnostic {
1510
+ function createDiagnosticForNodeArray ( nodes : NodeArray < Node > , message : DiagnosticMessage , arg0 ?: string | number , arg1 ?: string | number , arg2 ?: string | number ) : DiagnosticWithLocation {
1510
1511
const start = nodes . pos ;
1511
1512
return createFileDiagnostic ( sourceFile , start , nodes . end - start , message , arg0 , arg1 , arg2 ) ;
1512
1513
}
1513
1514
1514
1515
// Since these are syntactic diagnostics, parent might not have been set
1515
1516
// this means the sourceFile cannot be infered from the node
1516
- function createDiagnosticForNode ( node : Node , message : DiagnosticMessage , arg0 ?: string | number , arg1 ?: string | number , arg2 ?: string | number ) : Diagnostic {
1517
+ function createDiagnosticForNode ( node : Node , message : DiagnosticMessage , arg0 ?: string | number , arg1 ?: string | number , arg2 ?: string | number ) : DiagnosticWithLocation {
1517
1518
return createDiagnosticForNodeInSourceFile ( sourceFile , node , message , arg0 , arg1 , arg2 ) ;
1518
1519
}
1519
1520
} ) ;
1520
1521
}
1521
1522
1522
- function getDeclarationDiagnosticsWorker ( sourceFile : SourceFile | undefined , cancellationToken : CancellationToken ) : Diagnostic [ ] {
1523
+ function getDeclarationDiagnosticsWorker ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < DiagnosticWithLocation > {
1523
1524
return getAndCacheDiagnostics ( sourceFile , cancellationToken , cachedDeclarationDiagnosticsForFile , getDeclarationDiagnosticsForFileNoCache ) ;
1524
1525
}
1525
1526
@@ -1530,12 +1531,24 @@ namespace ts {
1530
1531
return ts . getDeclarationDiagnostics ( getEmitHost ( noop ) , resolver , sourceFile ) ;
1531
1532
} ) ;
1532
1533
}
1533
-
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 > ;
1534
1546
function getAndCacheDiagnostics (
1535
1547
sourceFile : SourceFile | undefined ,
1536
1548
cancellationToken : CancellationToken ,
1537
1549
cache : DiagnosticCache ,
1538
- getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => Diagnostic [ ] ) {
1550
+ getDiagnostics : ( sourceFile : SourceFile , cancellationToken : CancellationToken ) => DiagnosticWithLocation [ ] ,
1551
+ ) : ReadonlyArray < Diagnostic > {
1539
1552
1540
1553
const cachedResult = sourceFile
1541
1554
? cache . perFile && cache . perFile . get ( sourceFile . path )
@@ -1547,7 +1560,7 @@ namespace ts {
1547
1560
const result = getDiagnostics ( sourceFile , cancellationToken ) || emptyArray ;
1548
1561
if ( sourceFile ) {
1549
1562
if ( ! cache . perFile ) {
1550
- cache . perFile = createMap < Diagnostic [ ] > ( ) ;
1563
+ cache . perFile = createMap < DiagnosticWithLocation [ ] > ( ) ;
1551
1564
}
1552
1565
cache . perFile . set ( sourceFile . path , result ) ;
1553
1566
}
@@ -1557,7 +1570,7 @@ namespace ts {
1557
1570
return result ;
1558
1571
}
1559
1572
1560
- function getDeclarationDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : Diagnostic [ ] {
1573
+ function getDeclarationDiagnosticsForFile ( sourceFile : SourceFile , cancellationToken : CancellationToken ) : ReadonlyArray < DiagnosticWithLocation > {
1561
1574
return sourceFile . isDeclarationFile ? [ ] : getDeclarationDiagnosticsWorker ( sourceFile , cancellationToken ) ;
1562
1575
}
1563
1576
0 commit comments