Include guards on comment kind in pragma extraction (#23313)
This commit is contained in:
parent
b2e0c4bea6
commit
8a2b4646f0
|
@ -7603,7 +7603,7 @@ namespace ts {
|
|||
const tripleSlashXMLCommentStartRegEx = /^\/\/\/\s*<(\S+)\s.*?\/>/im;
|
||||
const singleLinePragmaRegEx = /^\/\/\/?\s*@(\S+)\s*(.*)\s*$/im;
|
||||
function extractPragmas(pragmas: PragmaPsuedoMapEntry[], range: CommentRange, text: string) {
|
||||
const tripleSlash = tripleSlashXMLCommentStartRegEx.exec(text);
|
||||
const tripleSlash = range.kind === SyntaxKind.SingleLineCommentTrivia && tripleSlashXMLCommentStartRegEx.exec(text);
|
||||
if (tripleSlash) {
|
||||
const name = tripleSlash[1].toLowerCase() as keyof PragmaPsuedoMap; // Technically unsafe cast, but we do it so the below check to make it safe typechecks
|
||||
const pragma = commentPragmas[name] as PragmaDefinition;
|
||||
|
@ -7640,15 +7640,17 @@ namespace ts {
|
|||
return;
|
||||
}
|
||||
|
||||
const singleLine = singleLinePragmaRegEx.exec(text);
|
||||
const singleLine = range.kind === SyntaxKind.SingleLineCommentTrivia && singleLinePragmaRegEx.exec(text);
|
||||
if (singleLine) {
|
||||
return addPragmaForMatch(pragmas, range, PragmaKindFlags.SingleLine, singleLine);
|
||||
}
|
||||
|
||||
const multiLinePragmaRegEx = /\s*@(\S+)\s*(.*)\s*$/gim; // Defined inline since it uses the "g" flag, which keeps a persistent index (for iterating)
|
||||
let multiLineMatch: RegExpExecArray;
|
||||
while (multiLineMatch = multiLinePragmaRegEx.exec(text)) {
|
||||
addPragmaForMatch(pragmas, range, PragmaKindFlags.MultiLine, multiLineMatch);
|
||||
if (range.kind === SyntaxKind.MultiLineCommentTrivia) {
|
||||
const multiLinePragmaRegEx = /\s*@(\S+)\s*(.*)\s*$/gim; // Defined inline since it uses the "g" flag, which keeps a persistent index (for iterating)
|
||||
let multiLineMatch: RegExpExecArray;
|
||||
while (multiLineMatch = multiLinePragmaRegEx.exec(text)) {
|
||||
addPragmaForMatch(pragmas, range, PragmaKindFlags.MultiLine, multiLineMatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
11
tests/baselines/reference/tripleSlashInCommentNotParsed.js
Normal file
11
tests/baselines/reference/tripleSlashInCommentNotParsed.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
//// [tripleSlashInCommentNotParsed.ts]
|
||||
/*
|
||||
/// <reference path="non-existing-file.d.ts" />
|
||||
*/
|
||||
void 0;
|
||||
|
||||
//// [tripleSlashInCommentNotParsed.js]
|
||||
/*
|
||||
/// <reference path="non-existing-file.d.ts" />
|
||||
*/
|
||||
void 0;
|
|
@ -0,0 +1,6 @@
|
|||
=== tests/cases/compiler/tripleSlashInCommentNotParsed.ts ===
|
||||
/*
|
||||
No type information for this code./// <reference path="non-existing-file.d.ts" />
|
||||
No type information for this code.*/
|
||||
No type information for this code.void 0;
|
||||
No type information for this code.
|
|
@ -0,0 +1,8 @@
|
|||
=== tests/cases/compiler/tripleSlashInCommentNotParsed.ts ===
|
||||
/*
|
||||
/// <reference path="non-existing-file.d.ts" />
|
||||
*/
|
||||
void 0;
|
||||
>void 0 : undefined
|
||||
>0 : 0
|
||||
|
4
tests/cases/compiler/tripleSlashInCommentNotParsed.ts
Normal file
4
tests/cases/compiler/tripleSlashInCommentNotParsed.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
/*
|
||||
/// <reference path="non-existing-file.d.ts" />
|
||||
*/
|
||||
void 0;
|
Loading…
Reference in a new issue