Skip to content

Commit f99893e

Browse files
committed
Don't use regex
1 parent ed54d9f commit f99893e

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

src/compiler/scanner.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,6 @@ const commentDirectiveRegExSingleLine = /^\/\/\/?\s*@(ts-expect-error|ts-ignore)
327327
*/
328328
const commentDirectiveRegExMultiLine = /^(?:\/|\*)*\s*@(ts-expect-error|ts-ignore)/;
329329

330-
/**
331-
* Test for whether a comment contains a JSDoc tag needed by the checker when run in tsc.
332-
*/
333-
const semanticJSDocTagRegEx = /@(?:see|link)/i;
334-
335330
function lookupInUnicodeMap(code: number, map: readonly number[]): boolean {
336331
// Bail out quickly if it couldn't possibly be in the map.
337332
if (code < map[0]) {
@@ -1834,6 +1829,7 @@ export function createScanner(languageVersion: ScriptTarget,
18341829
if (text.charCodeAt(pos + 1) === CharacterCodes.asterisk) {
18351830
pos += 2;
18361831
const isJSDoc = text.charCodeAt(pos) === CharacterCodes.asterisk && text.charCodeAt(pos + 1) !== CharacterCodes.slash;
1832+
let containsSeeOrLink = false;
18371833

18381834
let commentClosed = false;
18391835
let lastLineStart = tokenPos;
@@ -1846,6 +1842,36 @@ export function createScanner(languageVersion: ScriptTarget,
18461842
break;
18471843
}
18481844

1845+
if (skipJSDoc && isJSDoc && !containsSeeOrLink) {
1846+
if (ch === CharacterCodes.at) {
1847+
const ch1 = text.charCodeAt(pos + 1);
1848+
const ch2 = text.charCodeAt(pos + 2);
1849+
const ch3 = text.charCodeAt(pos + 3);
1850+
if (ch1 === CharacterCodes.s || ch1 === CharacterCodes.S) {
1851+
if (
1852+
(ch2 === CharacterCodes.e || ch2 === CharacterCodes.E)
1853+
&& (ch3 === CharacterCodes.e || ch3 === CharacterCodes.E)
1854+
) {
1855+
containsSeeOrLink = true;
1856+
pos += 3;
1857+
continue;
1858+
}
1859+
}
1860+
else if (ch1 === CharacterCodes.l || ch1 === CharacterCodes.L) {
1861+
const ch4 = text.charCodeAt(pos + 4);
1862+
if (
1863+
(ch2 === CharacterCodes.i || ch2 === CharacterCodes.I)
1864+
&& (ch3 === CharacterCodes.n || ch3 === CharacterCodes.N)
1865+
&& (ch4 === CharacterCodes.k || ch4 === CharacterCodes.K)
1866+
) {
1867+
containsSeeOrLink = true;
1868+
pos += 4;
1869+
continue;
1870+
}
1871+
}
1872+
}
1873+
}
1874+
18491875
pos++;
18501876

18511877
if (isLineBreak(ch)) {
@@ -1854,7 +1880,7 @@ export function createScanner(languageVersion: ScriptTarget,
18541880
}
18551881
}
18561882

1857-
if (isJSDoc && (!skipJSDoc || semanticJSDocTagRegEx.test(text.slice(tokenPos, pos)))) {
1883+
if (isJSDoc && (!skipJSDoc || containsSeeOrLink)) {
18581884
tokenFlags |= TokenFlags.PrecedingJSDocComment;
18591885
}
18601886

tests/cases/fourslash/jsdocDeprecated_suggestion_skipJSDoc.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,19 @@
1010
////function imDeprecated() {}
1111
////[|imDeprecated|]()
1212

13-
const [range] = test.ranges();
14-
verify.getSuggestionDiagnostics([]);
13+
/////**
14+
//// * {@see imDeprecated}
15+
//// * @deprecated
16+
//// */
17+
////function imDeprecated2() {}
18+
////[|imDeprecated2|]()
19+
20+
const [, range] = test.ranges();
21+
verify.getSuggestionDiagnostics([
22+
{
23+
"code": 6387,
24+
"message": "The signature '(): void' of 'imDeprecated2' is deprecated.",
25+
"reportsDeprecated": true,
26+
"range": range
27+
},
28+
]);

0 commit comments

Comments
 (0)