Skip to content

Commit a86be55

Browse files
authored
allow a colon directly after @ts-check/nocheck (#54893)
1 parent 61bf78f commit a86be55

19 files changed

+338
-8
lines changed

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10475,7 +10475,7 @@ function getNamedArgRegEx(name: string): RegExp {
1047510475
}
1047610476

1047710477
const tripleSlashXMLCommentStartRegEx = /^\/\/\/\s*<(\S+)\s.*?\/>/im;
10478-
const singleLinePragmaRegEx = /^\/\/\/?\s*@(\S+)\s*(.*)\s*$/im;
10478+
const singleLinePragmaRegEx = /^\/\/\/?\s*@([^\s:]+)(.*)\s*$/im;
1047910479
function extractPragmas(pragmas: PragmaPseudoMapEntry[], range: CommentRange, text: string) {
1048010480
const tripleSlash = range.kind === SyntaxKind.SingleLineCommentTrivia && tripleSlashXMLCommentStartRegEx.exec(text);
1048110481
if (tripleSlash) {

tests/baselines/reference/ts-expect-error.errors.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,12 @@ ts-expect-error.ts(40,2): error TS2367: This comparison appears to be unintentio
6767
!!! error TS2367: This comparison appears to be unintentional because the types 'true' and 'false' have no overlap.
6868
(({ a: true } as const).a === false); // error
6969
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70-
!!! error TS2367: This comparison appears to be unintentional because the types 'true' and 'false' have no overlap.
70+
!!! error TS2367: This comparison appears to be unintentional because the types 'true' and 'false' have no overlap.
71+
72+
// @ts-expect-error: additional commenting with no whitespace
73+
var invalidCommentedFancySingle: number = 'nope';
74+
75+
/*
76+
@ts-expect-error: additional commenting with no whitespace */
77+
var invalidCommentedFancyMulti: number = 'nope';
78+

tests/baselines/reference/ts-expect-error.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,15 @@ var validPlain: string = 'nope';
4040
(({ a: true } as const).a === false); // Should error
4141

4242
(({ a: true } as const).a === false); // error
43-
(({ a: true } as const).a === false); // error
43+
(({ a: true } as const).a === false); // error
44+
45+
// @ts-expect-error: additional commenting with no whitespace
46+
var invalidCommentedFancySingle: number = 'nope';
47+
48+
/*
49+
@ts-expect-error: additional commenting with no whitespace */
50+
var invalidCommentedFancyMulti: number = 'nope';
51+
4452

4553
//// [ts-expect-error.js]
4654
// @ts-expect-error additional commenting
@@ -71,3 +79,8 @@ var validPlain = 'nope';
7179
({ a: true }.a === false); // Should error
7280
({ a: true }.a === false); // error
7381
({ a: true }.a === false); // error
82+
// @ts-expect-error: additional commenting with no whitespace
83+
var invalidCommentedFancySingle = 'nope';
84+
/*
85+
@ts-expect-error: additional commenting with no whitespace */
86+
var invalidCommentedFancyMulti = 'nope';

tests/baselines/reference/ts-expect-error.symbols

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
=== ts-expect-error.ts ===
44
// @ts-expect-error additional commenting
55
var invalidCommentedFancySingle: number = 'nope';
6-
>invalidCommentedFancySingle : Symbol(invalidCommentedFancySingle, Decl(ts-expect-error.ts, 1, 3))
6+
>invalidCommentedFancySingle : Symbol(invalidCommentedFancySingle, Decl(ts-expect-error.ts, 1, 3), Decl(ts-expect-error.ts, 42, 3))
77

88
/*
99
@ts-expect-error additional commenting */
1010
var invalidCommentedFancyMulti: number = 'nope';
11-
>invalidCommentedFancyMulti : Symbol(invalidCommentedFancyMulti, Decl(ts-expect-error.ts, 5, 3))
11+
>invalidCommentedFancyMulti : Symbol(invalidCommentedFancyMulti, Decl(ts-expect-error.ts, 5, 3), Decl(ts-expect-error.ts, 46, 3))
1212

1313
// @ts-expect-error additional commenting
1414
var validCommentedFancySingle: string = 'nope';
@@ -71,3 +71,12 @@ var validPlain: string = 'nope';
7171
>const : Symbol(const)
7272
>a : Symbol(a, Decl(ts-expect-error.ts, 39, 3))
7373

74+
// @ts-expect-error: additional commenting with no whitespace
75+
var invalidCommentedFancySingle: number = 'nope';
76+
>invalidCommentedFancySingle : Symbol(invalidCommentedFancySingle, Decl(ts-expect-error.ts, 1, 3), Decl(ts-expect-error.ts, 42, 3))
77+
78+
/*
79+
@ts-expect-error: additional commenting with no whitespace */
80+
var invalidCommentedFancyMulti: number = 'nope';
81+
>invalidCommentedFancyMulti : Symbol(invalidCommentedFancyMulti, Decl(ts-expect-error.ts, 5, 3), Decl(ts-expect-error.ts, 46, 3))
82+

tests/baselines/reference/ts-expect-error.types

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,14 @@ var validPlain: string = 'nope';
106106
>a : true
107107
>false : false
108108

109+
// @ts-expect-error: additional commenting with no whitespace
110+
var invalidCommentedFancySingle: number = 'nope';
111+
>invalidCommentedFancySingle : number
112+
>'nope' : "nope"
113+
114+
/*
115+
@ts-expect-error: additional commenting with no whitespace */
116+
var invalidCommentedFancyMulti: number = 'nope';
117+
>invalidCommentedFancyMulti : number
118+
>'nope' : "nope"
119+

tests/baselines/reference/ts-ignore.errors.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ ts-ignore.ts(13,5): error TS2322: Type 'string' is not assignable to type 'numbe
1919
!!! error TS2322: Type 'string' is not assignable to type 'number'.
2020

2121
var validPlain: string = 'nope';
22+
23+
// @ts-ignore: with additional commenting
24+
var invalidCommentedFancy: number = 'nope';
25+
26+
// @ts-ignore: with additional commenting
27+
var validCommentedFancy: string = 'nope';
2228

tests/baselines/reference/ts-ignore.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ var validCommentedPlain: string = 'nope';
1616
var invalidPlain: number = 'nope';
1717

1818
var validPlain: string = 'nope';
19+
20+
// @ts-ignore: with additional commenting
21+
var invalidCommentedFancy: number = 'nope';
22+
23+
// @ts-ignore: with additional commenting
24+
var validCommentedFancy: string = 'nope';
1925

2026

2127
//// [ts-ignore.js]
@@ -29,3 +35,7 @@ var invalidCommentedPlain = 'nope';
2935
var validCommentedPlain = 'nope';
3036
var invalidPlain = 'nope';
3137
var validPlain = 'nope';
38+
// @ts-ignore: with additional commenting
39+
var invalidCommentedFancy = 'nope';
40+
// @ts-ignore: with additional commenting
41+
var validCommentedFancy = 'nope';

tests/baselines/reference/ts-ignore.symbols

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
=== ts-ignore.ts ===
44
// @ts-ignore with additional commenting
55
var invalidCommentedFancy: number = 'nope';
6-
>invalidCommentedFancy : Symbol(invalidCommentedFancy, Decl(ts-ignore.ts, 1, 3))
6+
>invalidCommentedFancy : Symbol(invalidCommentedFancy, Decl(ts-ignore.ts, 1, 3), Decl(ts-ignore.ts, 17, 3))
77

88
// @ts-ignore with additional commenting
99
var validCommentedFancy: string = 'nope';
10-
>validCommentedFancy : Symbol(validCommentedFancy, Decl(ts-ignore.ts, 4, 3))
10+
>validCommentedFancy : Symbol(validCommentedFancy, Decl(ts-ignore.ts, 4, 3), Decl(ts-ignore.ts, 20, 3))
1111

1212
// @ts-ignore
1313
var invalidCommentedPlain: number = 'nope';
@@ -23,3 +23,11 @@ var invalidPlain: number = 'nope';
2323
var validPlain: string = 'nope';
2424
>validPlain : Symbol(validPlain, Decl(ts-ignore.ts, 14, 3))
2525

26+
// @ts-ignore: with additional commenting
27+
var invalidCommentedFancy: number = 'nope';
28+
>invalidCommentedFancy : Symbol(invalidCommentedFancy, Decl(ts-ignore.ts, 1, 3), Decl(ts-ignore.ts, 17, 3))
29+
30+
// @ts-ignore: with additional commenting
31+
var validCommentedFancy: string = 'nope';
32+
>validCommentedFancy : Symbol(validCommentedFancy, Decl(ts-ignore.ts, 4, 3), Decl(ts-ignore.ts, 20, 3))
33+

tests/baselines/reference/ts-ignore.types

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,13 @@ var validPlain: string = 'nope';
2929
>validPlain : string
3030
>'nope' : "nope"
3131

32+
// @ts-ignore: with additional commenting
33+
var invalidCommentedFancy: number = 'nope';
34+
>invalidCommentedFancy : number
35+
>'nope' : "nope"
36+
37+
// @ts-ignore: with additional commenting
38+
var validCommentedFancy: string = 'nope';
39+
>validCommentedFancy : string
40+
>'nope' : "nope"
41+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//// [tests/cases/conformance/jsdoc/tsNoCheckForTypescriptComments1.ts] ////
2+
3+
//// [file.ts]
4+
// @ts-nocheck additional comments
5+
6+
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
7+
8+
export interface Aleph {
9+
q: number;
10+
}
11+
12+
export class Bet implements Aleph {
13+
q: string = 'lol'; // And so will this implements error
14+
}
15+
16+
17+
//// [file.js]
18+
"use strict";
19+
// @ts-nocheck additional comments
20+
Object.defineProperty(exports, "__esModule", { value: true });
21+
exports.Bet = exports.a = void 0;
22+
exports.a = 1 + {}; // This is an error, ofc, `Operator '+' cannot be applied to types '1' and '{}'`, which will be suppressed by the `nocheck` comment
23+
var Bet = /** @class */ (function () {
24+
function Bet() {
25+
this.q = 'lol'; // And so will this implements error
26+
}
27+
return Bet;
28+
}());
29+
exports.Bet = Bet;
30+
31+
32+
//// [file.d.ts]
33+
export declare const a: any;
34+
export interface Aleph {
35+
q: number;
36+
}
37+
export declare class Bet implements Aleph {
38+
q: string;
39+
}
40+
41+
42+
//// [DtsFileErrors]
43+
44+
45+
file.d.ts(6,5): error TS2416: Property 'q' in type 'Bet' is not assignable to the same property in base type 'Aleph'.
46+
Type 'string' is not assignable to type 'number'.
47+
48+
49+
==== file.d.ts (1 errors) ====
50+
export declare const a: any;
51+
export interface Aleph {
52+
q: number;
53+
}
54+
export declare class Bet implements Aleph {
55+
q: string;
56+
~
57+
!!! error TS2416: Property 'q' in type 'Bet' is not assignable to the same property in base type 'Aleph'.
58+
!!! error TS2416: Type 'string' is not assignable to type 'number'.
59+
}
60+

0 commit comments

Comments
 (0)