Don't compute suggestion diagnostics for lib files

The check applied to semantic diagnostics (and `checkSourceFile`) should
also apply to suggestion diagnostics.  Fixes assert.
This commit is contained in:
Andrew Casey 2018-08-07 17:57:47 -07:00
parent 1a05f13aef
commit daccc978a8
3 changed files with 13 additions and 8 deletions

View file

@ -314,6 +314,10 @@ namespace ts {
return node && getTypeArgumentConstraint(node);
},
getSuggestionDiagnostics: (file, ct) => {
if (skipTypeChecking(file, compilerOptions)) {
return emptyArray;
}
let diagnostics: DiagnosticWithLocation[] | undefined;
try {
// Record the cancellation token so it can be checked later on during checkSourceElement.
@ -26876,10 +26880,7 @@ namespace ts {
function checkSourceFileWorker(node: SourceFile) {
const links = getNodeLinks(node);
if (!(links.flags & NodeCheckFlags.TypeChecked)) {
// If skipLibCheck is enabled, skip type checking if file is a declaration file.
// If skipDefaultLibCheck is enabled, skip type checking if file contains a
// '/// <reference no-default-lib="true"/>' directive.
if (compilerOptions.skipLibCheck && node.isDeclarationFile || compilerOptions.skipDefaultLibCheck && node.hasNoDefaultLib) {
if (skipTypeChecking(node, compilerOptions)) {
return;
}

View file

@ -1476,10 +1476,7 @@ namespace ts {
function getSemanticDiagnosticsForFileNoCache(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] | undefined {
return runWithCancellationToken(() => {
// If skipLibCheck is enabled, skip reporting errors if file is a declaration file.
// If skipDefaultLibCheck is enabled, skip reporting errors if file contains a
// '/// <reference no-default-lib="true"/>' directive.
if (options.skipLibCheck && sourceFile.isDeclarationFile || options.skipDefaultLibCheck && sourceFile.hasNoDefaultLib) {
if (skipTypeChecking(sourceFile, options)) {
return emptyArray;
}

View file

@ -8212,4 +8212,11 @@ namespace ts {
// Include the `<>`
return { pos: typeParameters.pos - 1, end: typeParameters.end + 1 };
}
export function skipTypeChecking(sourceFile: SourceFile, options: CompilerOptions) {
// If skipLibCheck is enabled, skip reporting errors if file is a declaration file.
// If skipDefaultLibCheck is enabled, skip reporting errors if file contains a
// '/// <reference no-default-lib="true"/>' directive.
return options.skipLibCheck && sourceFile.isDeclarationFile || options.skipDefaultLibCheck && sourceFile.hasNoDefaultLib;
}
}