diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 82e4d8d006a..b55ba9b70fc 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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) { diff --git a/tests/baselines/reference/ts-expect-error.errors.txt b/tests/baselines/reference/ts-expect-error.errors.txt index c0e504bffb7..66ea5b9135c 100644 --- a/tests/baselines/reference/ts-expect-error.errors.txt +++ b/tests/baselines/reference/ts-expect-error.errors.txt @@ -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. \ No newline at end of file +!!! 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'; + \ No newline at end of file diff --git a/tests/baselines/reference/ts-expect-error.js b/tests/baselines/reference/ts-expect-error.js index bd877c112c6..e2f593287da 100644 --- a/tests/baselines/reference/ts-expect-error.js +++ b/tests/baselines/reference/ts-expect-error.js @@ -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'; diff --git a/tests/baselines/reference/ts-expect-error.symbols b/tests/baselines/reference/ts-expect-error.symbols index de03c62fbae..a3263542fdc 100644 --- a/tests/baselines/reference/ts-expect-error.symbols +++ b/tests/baselines/reference/ts-expect-error.symbols @@ -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)) + diff --git a/tests/baselines/reference/ts-expect-error.types b/tests/baselines/reference/ts-expect-error.types index 93c625bcc8c..659d21af9d9 100644 --- a/tests/baselines/reference/ts-expect-error.types +++ b/tests/baselines/reference/ts-expect-error.types @@ -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" + diff --git a/tests/baselines/reference/ts-ignore.errors.txt b/tests/baselines/reference/ts-ignore.errors.txt index c6bda312cba..9a243eff4d8 100644 --- a/tests/baselines/reference/ts-ignore.errors.txt +++ b/tests/baselines/reference/ts-ignore.errors.txt @@ -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'; \ No newline at end of file diff --git a/tests/baselines/reference/ts-ignore.js b/tests/baselines/reference/ts-ignore.js index b91deedd8a2..104bd7b350d 100644 --- a/tests/baselines/reference/ts-ignore.js +++ b/tests/baselines/reference/ts-ignore.js @@ -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'; diff --git a/tests/baselines/reference/ts-ignore.symbols b/tests/baselines/reference/ts-ignore.symbols index 0268ba8b83e..de62af9cbab 100644 --- a/tests/baselines/reference/ts-ignore.symbols +++ b/tests/baselines/reference/ts-ignore.symbols @@ -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)) + diff --git a/tests/baselines/reference/ts-ignore.types b/tests/baselines/reference/ts-ignore.types index 738dd01958f..e4407d405e9 100644 --- a/tests/baselines/reference/ts-ignore.types +++ b/tests/baselines/reference/ts-ignore.types @@ -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" + diff --git a/tests/baselines/reference/tsNoCheckForTypescriptComments1.js b/tests/baselines/reference/tsNoCheckForTypescriptComments1.js new file mode 100644 index 00000000000..cc17a5ace29 --- /dev/null +++ b/tests/baselines/reference/tsNoCheckForTypescriptComments1.js @@ -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'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/tsNoCheckForTypescriptComments1.symbols b/tests/baselines/reference/tsNoCheckForTypescriptComments1.symbols new file mode 100644 index 00000000000..a91636402cc --- /dev/null +++ b/tests/baselines/reference/tsNoCheckForTypescriptComments1.symbols @@ -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)) +} + diff --git a/tests/baselines/reference/tsNoCheckForTypescriptComments1.types b/tests/baselines/reference/tsNoCheckForTypescriptComments1.types new file mode 100644 index 00000000000..662f44bff07 --- /dev/null +++ b/tests/baselines/reference/tsNoCheckForTypescriptComments1.types @@ -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" +} + diff --git a/tests/baselines/reference/tsNoCheckForTypescriptComments2.js b/tests/baselines/reference/tsNoCheckForTypescriptComments2.js new file mode 100644 index 00000000000..ea60cfa4687 --- /dev/null +++ b/tests/baselines/reference/tsNoCheckForTypescriptComments2.js @@ -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'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/tsNoCheckForTypescriptComments2.symbols b/tests/baselines/reference/tsNoCheckForTypescriptComments2.symbols new file mode 100644 index 00000000000..f4a18b86660 --- /dev/null +++ b/tests/baselines/reference/tsNoCheckForTypescriptComments2.symbols @@ -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)) +} + diff --git a/tests/baselines/reference/tsNoCheckForTypescriptComments2.types b/tests/baselines/reference/tsNoCheckForTypescriptComments2.types new file mode 100644 index 00000000000..5bf5c1bc6a7 --- /dev/null +++ b/tests/baselines/reference/tsNoCheckForTypescriptComments2.types @@ -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" +} + diff --git a/tests/cases/conformance/directives/ts-expect-error.ts b/tests/cases/conformance/directives/ts-expect-error.ts index 3ae0527e730..4702cca6bbc 100644 --- a/tests/cases/conformance/directives/ts-expect-error.ts +++ b/tests/cases/conformance/directives/ts-expect-error.ts @@ -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 \ No newline at end of file +(({ 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'; diff --git a/tests/cases/conformance/directives/ts-ignore.ts b/tests/cases/conformance/directives/ts-ignore.ts index 0b058f9ea3b..496b685580e 100644 --- a/tests/cases/conformance/directives/ts-ignore.ts +++ b/tests/cases/conformance/directives/ts-ignore.ts @@ -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'; diff --git a/tests/cases/conformance/jsdoc/tsNoCheckForTypescriptComments1.ts b/tests/cases/conformance/jsdoc/tsNoCheckForTypescriptComments1.ts new file mode 100644 index 00000000000..8028edf131d --- /dev/null +++ b/tests/cases/conformance/jsdoc/tsNoCheckForTypescriptComments1.ts @@ -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 +} diff --git a/tests/cases/conformance/jsdoc/tsNoCheckForTypescriptComments2.ts b/tests/cases/conformance/jsdoc/tsNoCheckForTypescriptComments2.ts new file mode 100644 index 00000000000..d1d79299e91 --- /dev/null +++ b/tests/cases/conformance/jsdoc/tsNoCheckForTypescriptComments2.ts @@ -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 +}