allow a colon directly after @ts-check/nocheck (#54893)

This commit is contained in:
Kyℓe Hensel
2023-07-22 04:16:31 +12:00
committed by GitHub
parent 61bf78f3c2
commit a86be554ab
19 changed files with 338 additions and 8 deletions

View File

@@ -10475,7 +10475,7 @@ function getNamedArgRegEx(name: string): RegExp {
}
const tripleSlashXMLCommentStartRegEx = /^\/\/\/\s*<(\S+)\s.*?\/>/im;
const singleLinePragmaRegEx = /^\/\/\/?\s*@(\S+)\s*(.*)\s*$/im;
const singleLinePragmaRegEx = /^\/\/\/?\s*@([^\s:]+)(.*)\s*$/im;
function extractPragmas(pragmas: PragmaPseudoMapEntry[], range: CommentRange, text: string) {
const tripleSlash = range.kind === SyntaxKind.SingleLineCommentTrivia && tripleSlashXMLCommentStartRegEx.exec(text);
if (tripleSlash) {

View File

@@ -67,4 +67,12 @@ ts-expect-error.ts(40,2): error TS2367: This comparison appears to be unintentio
!!! error TS2367: This comparison appears to be unintentional because the types 'true' and 'false' have no overlap.
(({ a: true } as const).a === false); // error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2367: This comparison appears to be unintentional because the types 'true' and 'false' have no overlap.
!!! error TS2367: This comparison appears to be unintentional because the types 'true' and 'false' have no overlap.
// @ts-expect-error: additional commenting with no whitespace
var invalidCommentedFancySingle: number = 'nope';
/*
@ts-expect-error: additional commenting with no whitespace */
var invalidCommentedFancyMulti: number = 'nope';

View File

@@ -40,7 +40,15 @@ var validPlain: string = 'nope';
(({ a: true } as const).a === false); // Should error
(({ a: true } as const).a === false); // error
(({ a: true } as const).a === false); // error
(({ a: true } as const).a === false); // error
// @ts-expect-error: additional commenting with no whitespace
var invalidCommentedFancySingle: number = 'nope';
/*
@ts-expect-error: additional commenting with no whitespace */
var invalidCommentedFancyMulti: number = 'nope';
//// [ts-expect-error.js]
// @ts-expect-error additional commenting
@@ -71,3 +79,8 @@ var validPlain = 'nope';
({ a: true }.a === false); // Should error
({ a: true }.a === false); // error
({ a: true }.a === false); // error
// @ts-expect-error: additional commenting with no whitespace
var invalidCommentedFancySingle = 'nope';
/*
@ts-expect-error: additional commenting with no whitespace */
var invalidCommentedFancyMulti = 'nope';

View File

@@ -3,12 +3,12 @@
=== ts-expect-error.ts ===
// @ts-expect-error additional commenting
var invalidCommentedFancySingle: number = 'nope';
>invalidCommentedFancySingle : Symbol(invalidCommentedFancySingle, Decl(ts-expect-error.ts, 1, 3))
>invalidCommentedFancySingle : Symbol(invalidCommentedFancySingle, Decl(ts-expect-error.ts, 1, 3), Decl(ts-expect-error.ts, 42, 3))
/*
@ts-expect-error additional commenting */
var invalidCommentedFancyMulti: number = 'nope';
>invalidCommentedFancyMulti : Symbol(invalidCommentedFancyMulti, Decl(ts-expect-error.ts, 5, 3))
>invalidCommentedFancyMulti : Symbol(invalidCommentedFancyMulti, Decl(ts-expect-error.ts, 5, 3), Decl(ts-expect-error.ts, 46, 3))
// @ts-expect-error additional commenting
var validCommentedFancySingle: string = 'nope';
@@ -71,3 +71,12 @@ var validPlain: string = 'nope';
>const : Symbol(const)
>a : Symbol(a, Decl(ts-expect-error.ts, 39, 3))
// @ts-expect-error: additional commenting with no whitespace
var invalidCommentedFancySingle: number = 'nope';
>invalidCommentedFancySingle : Symbol(invalidCommentedFancySingle, Decl(ts-expect-error.ts, 1, 3), Decl(ts-expect-error.ts, 42, 3))
/*
@ts-expect-error: additional commenting with no whitespace */
var invalidCommentedFancyMulti: number = 'nope';
>invalidCommentedFancyMulti : Symbol(invalidCommentedFancyMulti, Decl(ts-expect-error.ts, 5, 3), Decl(ts-expect-error.ts, 46, 3))

View File

@@ -106,3 +106,14 @@ var validPlain: string = 'nope';
>a : true
>false : false
// @ts-expect-error: additional commenting with no whitespace
var invalidCommentedFancySingle: number = 'nope';
>invalidCommentedFancySingle : number
>'nope' : "nope"
/*
@ts-expect-error: additional commenting with no whitespace */
var invalidCommentedFancyMulti: number = 'nope';
>invalidCommentedFancyMulti : number
>'nope' : "nope"

View File

@@ -19,4 +19,10 @@ ts-ignore.ts(13,5): error TS2322: Type 'string' is not assignable to type 'numbe
!!! error TS2322: Type 'string' is not assignable to type 'number'.
var validPlain: string = 'nope';
// @ts-ignore: with additional commenting
var invalidCommentedFancy: number = 'nope';
// @ts-ignore: with additional commenting
var validCommentedFancy: string = 'nope';

View File

@@ -16,6 +16,12 @@ var validCommentedPlain: string = 'nope';
var invalidPlain: number = 'nope';
var validPlain: string = 'nope';
// @ts-ignore: with additional commenting
var invalidCommentedFancy: number = 'nope';
// @ts-ignore: with additional commenting
var validCommentedFancy: string = 'nope';
//// [ts-ignore.js]
@@ -29,3 +35,7 @@ var invalidCommentedPlain = 'nope';
var validCommentedPlain = 'nope';
var invalidPlain = 'nope';
var validPlain = 'nope';
// @ts-ignore: with additional commenting
var invalidCommentedFancy = 'nope';
// @ts-ignore: with additional commenting
var validCommentedFancy = 'nope';

View File

@@ -3,11 +3,11 @@
=== ts-ignore.ts ===
// @ts-ignore with additional commenting
var invalidCommentedFancy: number = 'nope';
>invalidCommentedFancy : Symbol(invalidCommentedFancy, Decl(ts-ignore.ts, 1, 3))
>invalidCommentedFancy : Symbol(invalidCommentedFancy, Decl(ts-ignore.ts, 1, 3), Decl(ts-ignore.ts, 17, 3))
// @ts-ignore with additional commenting
var validCommentedFancy: string = 'nope';
>validCommentedFancy : Symbol(validCommentedFancy, Decl(ts-ignore.ts, 4, 3))
>validCommentedFancy : Symbol(validCommentedFancy, Decl(ts-ignore.ts, 4, 3), Decl(ts-ignore.ts, 20, 3))
// @ts-ignore
var invalidCommentedPlain: number = 'nope';
@@ -23,3 +23,11 @@ var invalidPlain: number = 'nope';
var validPlain: string = 'nope';
>validPlain : Symbol(validPlain, Decl(ts-ignore.ts, 14, 3))
// @ts-ignore: with additional commenting
var invalidCommentedFancy: number = 'nope';
>invalidCommentedFancy : Symbol(invalidCommentedFancy, Decl(ts-ignore.ts, 1, 3), Decl(ts-ignore.ts, 17, 3))
// @ts-ignore: with additional commenting
var validCommentedFancy: string = 'nope';
>validCommentedFancy : Symbol(validCommentedFancy, Decl(ts-ignore.ts, 4, 3), Decl(ts-ignore.ts, 20, 3))

View File

@@ -29,3 +29,13 @@ var validPlain: string = 'nope';
>validPlain : string
>'nope' : "nope"
// @ts-ignore: with additional commenting
var invalidCommentedFancy: number = 'nope';
>invalidCommentedFancy : number
>'nope' : "nope"
// @ts-ignore: with additional commenting
var validCommentedFancy: string = 'nope';
>validCommentedFancy : string
>'nope' : "nope"

View File

@@ -0,0 +1,60 @@
//// [tests/cases/conformance/jsdoc/tsNoCheckForTypescriptComments1.ts] ////
//// [file.ts]
// @ts-nocheck additional comments
export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
export interface Aleph {
q: number;
}
export class Bet implements Aleph {
q: string = 'lol'; // And so will this implements error
}
//// [file.js]
"use strict";
// @ts-nocheck additional comments
Object.defineProperty(exports, "__esModule", { value: true });
exports.Bet = exports.a = void 0;
exports.a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
var Bet = /** @class */ (function () {
function Bet() {
this.q = 'lol'; // And so will this implements error
}
return Bet;
}());
exports.Bet = Bet;
//// [file.d.ts]
export declare const a: any;
export interface Aleph {
q: number;
}
export declare class Bet implements Aleph {
q: string;
}
//// [DtsFileErrors]
file.d.ts(6,5): error TS2416: Property 'q' in type 'Bet' is not assignable to the same property in base type 'Aleph'.
Type 'string' is not assignable to type 'number'.
==== file.d.ts (1 errors) ====
export declare const a: any;
export interface Aleph {
q: number;
}
export declare class Bet implements Aleph {
q: string;
~
!!! error TS2416: Property 'q' in type 'Bet' is not assignable to the same property in base type 'Aleph'.
!!! error TS2416: Type 'string' is not assignable to type 'number'.
}

View File

@@ -0,0 +1,23 @@
//// [tests/cases/conformance/jsdoc/tsNoCheckForTypescriptComments1.ts] ////
=== file.ts ===
// @ts-nocheck additional comments
export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
>a : Symbol(a, Decl(file.ts, 2, 12))
export interface Aleph {
>Aleph : Symbol(Aleph, Decl(file.ts, 2, 24))
q: number;
>q : Symbol(Aleph.q, Decl(file.ts, 4, 24))
}
export class Bet implements Aleph {
>Bet : Symbol(Bet, Decl(file.ts, 6, 1))
>Aleph : Symbol(Aleph, Decl(file.ts, 2, 24))
q: string = 'lol'; // And so will this implements error
>q : Symbol(Bet.q, Decl(file.ts, 8, 35))
}

View File

@@ -0,0 +1,24 @@
//// [tests/cases/conformance/jsdoc/tsNoCheckForTypescriptComments1.ts] ////
=== file.ts ===
// @ts-nocheck additional comments
export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
>a : any
>1 + {} : any
>1 : 1
>{} : {}
export interface Aleph {
q: number;
>q : number
}
export class Bet implements Aleph {
>Bet : Bet
q: string = 'lol'; // And so will this implements error
>q : string
>'lol' : "lol"
}

View File

@@ -0,0 +1,60 @@
//// [tests/cases/conformance/jsdoc/tsNoCheckForTypescriptComments2.ts] ////
//// [file.ts]
// @ts-nocheck: additional comments
export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
export interface Aleph {
q: number;
}
export class Bet implements Aleph {
q: string = "lol" // And so will this implements error
}
//// [file.js]
"use strict";
// @ts-nocheck: additional comments
Object.defineProperty(exports, "__esModule", { value: true });
exports.Bet = exports.a = void 0;
exports.a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
var Bet = /** @class */ (function () {
function Bet() {
this.q = "lol"; // And so will this implements error
}
return Bet;
}());
exports.Bet = Bet;
//// [file.d.ts]
export declare const a: any;
export interface Aleph {
q: number;
}
export declare class Bet implements Aleph {
q: string;
}
//// [DtsFileErrors]
file.d.ts(6,5): error TS2416: Property 'q' in type 'Bet' is not assignable to the same property in base type 'Aleph'.
Type 'string' is not assignable to type 'number'.
==== file.d.ts (1 errors) ====
export declare const a: any;
export interface Aleph {
q: number;
}
export declare class Bet implements Aleph {
q: string;
~
!!! error TS2416: Property 'q' in type 'Bet' is not assignable to the same property in base type 'Aleph'.
!!! error TS2416: Type 'string' is not assignable to type 'number'.
}

View File

@@ -0,0 +1,23 @@
//// [tests/cases/conformance/jsdoc/tsNoCheckForTypescriptComments2.ts] ////
=== file.ts ===
// @ts-nocheck: additional comments
export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
>a : Symbol(a, Decl(file.ts, 2, 12))
export interface Aleph {
>Aleph : Symbol(Aleph, Decl(file.ts, 2, 24))
q: number;
>q : Symbol(Aleph.q, Decl(file.ts, 4, 24))
}
export class Bet implements Aleph {
>Bet : Symbol(Bet, Decl(file.ts, 6, 1))
>Aleph : Symbol(Aleph, Decl(file.ts, 2, 24))
q: string = "lol" // And so will this implements error
>q : Symbol(Bet.q, Decl(file.ts, 8, 35))
}

View File

@@ -0,0 +1,24 @@
//// [tests/cases/conformance/jsdoc/tsNoCheckForTypescriptComments2.ts] ////
=== file.ts ===
// @ts-nocheck: additional comments
export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
>a : any
>1 + {} : any
>1 : 1
>{} : {}
export interface Aleph {
q: number;
>q : number
}
export class Bet implements Aleph {
>Bet : Bet
q: string = "lol" // And so will this implements error
>q : string
>"lol" : "lol"
}

View File

@@ -37,4 +37,11 @@ var validPlain: string = 'nope';
(({ a: true } as const).a === false); // Should error
(({ a: true } as const).a === false); // error
(({ a: true } as const).a === false); // error
(({ a: true } as const).a === false); // error
// @ts-expect-error: additional commenting with no whitespace
var invalidCommentedFancySingle: number = 'nope';
/*
@ts-expect-error: additional commenting with no whitespace */
var invalidCommentedFancyMulti: number = 'nope';

View File

@@ -13,3 +13,9 @@ var validCommentedPlain: string = 'nope';
var invalidPlain: number = 'nope';
var validPlain: string = 'nope';
// @ts-ignore: with additional commenting
var invalidCommentedFancy: number = 'nope';
// @ts-ignore: with additional commenting
var validCommentedFancy: string = 'nope';

View File

@@ -0,0 +1,14 @@
// @declaration: true
// @filename: file.ts
// @ts-nocheck additional comments
export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
export interface Aleph {
q: number;
}
export class Bet implements Aleph {
q: string = 'lol'; // And so will this implements error
}

View File

@@ -0,0 +1,14 @@
// @declaration: true
// @filename: file.ts
// @ts-nocheck: additional comments
export const a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
export interface Aleph {
q: number;
}
export class Bet implements Aleph {
q: string = "lol" // And so will this implements error
}