diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 24a1a0eb106b3..cb43475ffdd29 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -3,7 +3,7 @@ /// namespace ts { - const ignoreDiagnosticCommentRegEx = /(^\s*$)|(^\s*\/\/\/?\s*(@ts-ignore)?)/; + const ignoreDiagnosticCommentRegEx = /(^\s*$)|(^\s*\/\/\/?\s*(@ts-ignore)?(?:\s+((?:(?:TS\d+)\s*,\s*)*TS\d+))?)/; export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName = "tsconfig.json"): string | undefined { return forEachAncestorDirectory(searchPath, ancestor => { @@ -1110,7 +1110,7 @@ namespace ts { // otherwise, using options specified in '--lib' instead of '--target' default library file const equalityComparer = host.useCaseSensitiveFileNames() ? equateStringsCaseSensitive : equateStringsCaseInsensitive; if (!options.lib) { - return equalityComparer(file.fileName, getDefaultLibraryFileName()); + return equalityComparer(file.fileName, getDefaultLibraryFileName()); } else { return forEach(options.lib, libFileName => equalityComparer(file.fileName, combinePaths(defaultLibraryPath, libFileName))); @@ -1323,6 +1323,11 @@ namespace ts { } if (result[3]) { // @ts-ignore + const ignoreOptions = result[4]; + if (ignoreOptions) { + const errorCodes = ignoreOptions.split(/\s*,\s*/g); + return errorCodes.indexOf("TS" + diagnostic.code) === -1; + } return false; } line--; diff --git a/tests/baselines/reference/checkJsFiles_skipDiagnostics.errors.txt b/tests/baselines/reference/checkJsFiles_skipDiagnostics.errors.txt new file mode 100644 index 0000000000000..2b3461bab2b5f --- /dev/null +++ b/tests/baselines/reference/checkJsFiles_skipDiagnostics.errors.txt @@ -0,0 +1,49 @@ +tests/cases/compiler/a.js(43,1): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures. + + +==== tests/cases/compiler/a.js (1 errors) ==== + var x = 0; + + + /// @ts-ignore + x(); + + /// @ts-ignore + x(); + + /// @ts-ignore + x( + 2, + 3); + + + + // @ts-ignore + // come comment + // some other comment + + // @anohter + + x(); + + + + // @ts-ignore: no call signature + x(); + + // @ts-ignore TS2349 + x(); + + // @ts-ignore TS2349, TS2350 + x(); + + // @ts-ignore TS2349 , TS2350 // space before comma and additioanl comment + x(); + + // @ts-ignore TS2349 , TS2350, // trailing comma + x(); + + // @ts-ignore TS2350 here should be error + x(); + ~~~ +!!! error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures. \ No newline at end of file diff --git a/tests/baselines/reference/checkJsFiles_skipDiagnostics.symbols b/tests/baselines/reference/checkJsFiles_skipDiagnostics.symbols index 5d9aa8c53c563..5c10b6a9fd753 100644 --- a/tests/baselines/reference/checkJsFiles_skipDiagnostics.symbols +++ b/tests/baselines/reference/checkJsFiles_skipDiagnostics.symbols @@ -35,3 +35,23 @@ x(); x(); >x : Symbol(x, Decl(a.js, 0, 3)) +// @ts-ignore TS2349 +x(); +>x : Symbol(x, Decl(a.js, 0, 3)) + +// @ts-ignore TS2349, TS2350 +x(); +>x : Symbol(x, Decl(a.js, 0, 3)) + +// @ts-ignore TS2349 , TS2350 // space before comma and additioanl comment +x(); +>x : Symbol(x, Decl(a.js, 0, 3)) + +// @ts-ignore TS2349 , TS2350, // trailing comma +x(); +>x : Symbol(x, Decl(a.js, 0, 3)) + +// @ts-ignore TS2350 here should be error +x(); +>x : Symbol(x, Decl(a.js, 0, 3)) + diff --git a/tests/baselines/reference/checkJsFiles_skipDiagnostics.types b/tests/baselines/reference/checkJsFiles_skipDiagnostics.types index a07bf43901b32..d5da5e760ea6c 100644 --- a/tests/baselines/reference/checkJsFiles_skipDiagnostics.types +++ b/tests/baselines/reference/checkJsFiles_skipDiagnostics.types @@ -44,3 +44,28 @@ x(); >x() : any >x : number +// @ts-ignore TS2349 +x(); +>x() : any +>x : number + +// @ts-ignore TS2349, TS2350 +x(); +>x() : any +>x : number + +// @ts-ignore TS2349 , TS2350 // space before comma and additioanl comment +x(); +>x() : any +>x : number + +// @ts-ignore TS2349 , TS2350, // trailing comma +x(); +>x() : any +>x : number + +// @ts-ignore TS2350 here should be error +x(); +>x() : any +>x : number + diff --git a/tests/cases/compiler/checkJsFiles_skipDiagnostics.ts b/tests/cases/compiler/checkJsFiles_skipDiagnostics.ts index 48364c6a592ec..7c15563e19af0 100644 --- a/tests/cases/compiler/checkJsFiles_skipDiagnostics.ts +++ b/tests/cases/compiler/checkJsFiles_skipDiagnostics.ts @@ -30,4 +30,19 @@ x(); // @ts-ignore: no call signature +x(); + +// @ts-ignore TS2349 +x(); + +// @ts-ignore TS2349, TS2350 +x(); + +// @ts-ignore TS2349 , TS2350 // space before comma and additioanl comment +x(); + +// @ts-ignore TS2349 , TS2350, // trailing comma +x(); + +// @ts-ignore TS2350 here should be error x(); \ No newline at end of file