Skip to content

Commit daccc97

Browse files
committed
Don't compute suggestion diagnostics for lib files
The check applied to semantic diagnostics (and `checkSourceFile`) should also apply to suggestion diagnostics. Fixes assert.
1 parent 1a05f13 commit daccc97

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ namespace ts {
314314
return node && getTypeArgumentConstraint(node);
315315
},
316316
getSuggestionDiagnostics: (file, ct) => {
317+
if (skipTypeChecking(file, compilerOptions)) {
318+
return emptyArray;
319+
}
320+
317321
let diagnostics: DiagnosticWithLocation[] | undefined;
318322
try {
319323
// Record the cancellation token so it can be checked later on during checkSourceElement.
@@ -26876,10 +26880,7 @@ namespace ts {
2687626880
function checkSourceFileWorker(node: SourceFile) {
2687726881
const links = getNodeLinks(node);
2687826882
if (!(links.flags & NodeCheckFlags.TypeChecked)) {
26879-
// If skipLibCheck is enabled, skip type checking if file is a declaration file.
26880-
// If skipDefaultLibCheck is enabled, skip type checking if file contains a
26881-
// '/// <reference no-default-lib="true"/>' directive.
26882-
if (compilerOptions.skipLibCheck && node.isDeclarationFile || compilerOptions.skipDefaultLibCheck && node.hasNoDefaultLib) {
26883+
if (skipTypeChecking(node, compilerOptions)) {
2688326884
return;
2688426885
}
2688526886

src/compiler/program.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,10 +1476,7 @@ namespace ts {
14761476

14771477
function getSemanticDiagnosticsForFileNoCache(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] | undefined {
14781478
return runWithCancellationToken(() => {
1479-
// If skipLibCheck is enabled, skip reporting errors if file is a declaration file.
1480-
// If skipDefaultLibCheck is enabled, skip reporting errors if file contains a
1481-
// '/// <reference no-default-lib="true"/>' directive.
1482-
if (options.skipLibCheck && sourceFile.isDeclarationFile || options.skipDefaultLibCheck && sourceFile.hasNoDefaultLib) {
1479+
if (skipTypeChecking(sourceFile, options)) {
14831480
return emptyArray;
14841481
}
14851482

src/compiler/utilities.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8212,4 +8212,11 @@ namespace ts {
82128212
// Include the `<>`
82138213
return { pos: typeParameters.pos - 1, end: typeParameters.end + 1 };
82148214
}
8215+
8216+
export function skipTypeChecking(sourceFile: SourceFile, options: CompilerOptions) {
8217+
// If skipLibCheck is enabled, skip reporting errors if file is a declaration file.
8218+
// If skipDefaultLibCheck is enabled, skip reporting errors if file contains a
8219+
// '/// <reference no-default-lib="true"/>' directive.
8220+
return options.skipLibCheck && sourceFile.isDeclarationFile || options.skipDefaultLibCheck && sourceFile.hasNoDefaultLib;
8221+
}
82158222
}

0 commit comments

Comments
 (0)