don't emit "unused @ts-expect-error" in unchecked js files (#40046)

* don't emit unused ts-expect-error in unchecked js files

* simplify code
This commit is contained in:
Kyℓe Hensel
2020-08-25 11:04:23 -07:00
committed by GitHub
parent 2ff70f0b09
commit c5446d1a47
12 changed files with 103 additions and 3 deletions
+3 -3
View File
@@ -1747,13 +1747,13 @@ namespace ts {
const bindDiagnostics: readonly Diagnostic[] = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : emptyArray;
const checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : emptyArray;
return getMergedBindAndCheckDiagnostics(sourceFile, bindDiagnostics, checkDiagnostics, isCheckJs ? sourceFile.jsDocDiagnostics : undefined);
return getMergedBindAndCheckDiagnostics(sourceFile, includeBindAndCheckDiagnostics, bindDiagnostics, checkDiagnostics, isCheckJs ? sourceFile.jsDocDiagnostics : undefined);
});
}
function getMergedBindAndCheckDiagnostics(sourceFile: SourceFile, ...allDiagnostics: (readonly Diagnostic[] | undefined)[]) {
function getMergedBindAndCheckDiagnostics(sourceFile: SourceFile, includeBindAndCheckDiagnostics: boolean, ...allDiagnostics: (readonly Diagnostic[] | undefined)[]) {
const flatDiagnostics = flatten(allDiagnostics);
if (!sourceFile.commentDirectives?.length) {
if (!includeBindAndCheckDiagnostics || !sourceFile.commentDirectives?.length) {
return flatDiagnostics;
}
@@ -0,0 +1,11 @@
tests/cases/conformance/directives/a.js(3,1): error TS2578: Unused '@ts-expect-error' directive.
==== tests/cases/conformance/directives/a.js (1 errors) ====
// there should be a "Unused @ts-expect-error" error since js files are being checked
// @ts-expect-error
~~~~~~~~~~~~~~~~~~~
!!! error TS2578: Unused '@ts-expect-error' directive.
const a = 1;
@@ -0,0 +1,7 @@
=== tests/cases/conformance/directives/a.js ===
// there should be a "Unused @ts-expect-error" error since js files are being checked
// @ts-expect-error
const a = 1;
>a : Symbol(a, Decl(a.js, 3, 5))
@@ -0,0 +1,8 @@
=== tests/cases/conformance/directives/a.js ===
// there should be a "Unused @ts-expect-error" error since js files are being checked
// @ts-expect-error
const a = 1;
>a : 1
>1 : 1
@@ -0,0 +1,7 @@
=== tests/cases/conformance/directives/a.js ===
// there should not be a "Unused @ts-expect-error" error since js files are not being checked
// @ts-expect-error
const a = 1;
>a : Symbol(a, Decl(a.js, 3, 5))
@@ -0,0 +1,8 @@
=== tests/cases/conformance/directives/a.js ===
// there should not be a "Unused @ts-expect-error" error since js files are not being checked
// @ts-expect-error
const a = 1;
>a : 1
>1 : 1
@@ -0,0 +1,14 @@
//// [ts-expect-error-nocheck.ts]
// @ts-nocheck
// there should not be a "Unused @ts-expect-error" error due to the // @ts-nocheck
// @ts-expect-error
const a = 1;
//// [ts-expect-error-nocheck.js]
// @ts-nocheck
// there should not be a "Unused @ts-expect-error" error due to the // @ts-nocheck
// @ts-expect-error
var a = 1;
@@ -0,0 +1,9 @@
=== tests/cases/conformance/directives/ts-expect-error-nocheck.ts ===
// @ts-nocheck
// there should not be a "Unused @ts-expect-error" error due to the // @ts-nocheck
// @ts-expect-error
const a = 1;
>a : Symbol(a, Decl(ts-expect-error-nocheck.ts, 5, 5))
@@ -0,0 +1,10 @@
=== tests/cases/conformance/directives/ts-expect-error-nocheck.ts ===
// @ts-nocheck
// there should not be a "Unused @ts-expect-error" error due to the // @ts-nocheck
// @ts-expect-error
const a = 1;
>a : 1
>1 : 1
@@ -0,0 +1,10 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true
// @fileName: a.js
// there should be a "Unused @ts-expect-error" error since js files are being checked
// @ts-expect-error
const a = 1;
@@ -0,0 +1,10 @@
// @allowJs: true
// @checkJs: false
// @noEmit: true
// @fileName: a.js
// there should not be a "Unused @ts-expect-error" error since js files are not being checked
// @ts-expect-error
const a = 1;
@@ -0,0 +1,6 @@
// @ts-nocheck
// there should not be a "Unused @ts-expect-error" error due to the // @ts-nocheck
// @ts-expect-error
const a = 1;