mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 04:43:37 -05:00
@link parses trailing <...> as part of linkName (#46450)
Similar to #46428. Fixes #44818
This commit is contained in:
committed by
GitHub
parent
0d022130be
commit
f2e5947935
@@ -2315,22 +2315,36 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
const symbol = checker?.getSymbolAtLocation(link.name);
|
||||
const trailingParen = link.text.indexOf("()") === 0;
|
||||
const name = getTextOfNode(link.name) + (trailingParen ? "()" : "");
|
||||
const text = trailingParen ? link.text.slice(2) : link.text;
|
||||
const suffix = findLinkNameEnd(link.text);
|
||||
const name = getTextOfNode(link.name) + link.text.slice(0, suffix);
|
||||
const text = link.text.slice(suffix);
|
||||
const decl = symbol?.valueDeclaration || symbol?.declarations?.[0];
|
||||
if (decl) {
|
||||
parts.push(linkNamePart(name, decl));
|
||||
if (text) parts.push(linkTextPart(text));
|
||||
}
|
||||
else {
|
||||
parts.push(linkTextPart(name + (trailingParen ? "" : " ") + text));
|
||||
parts.push(linkTextPart(name + (suffix ? "" : " ") + text));
|
||||
}
|
||||
}
|
||||
parts.push(linkPart("}"));
|
||||
return parts;
|
||||
}
|
||||
|
||||
function findLinkNameEnd(text: string) {
|
||||
if (text.indexOf("()") === 0) return 2;
|
||||
if (text[0] !== "<") return 0;
|
||||
let brackets = 0;
|
||||
let i = 0;
|
||||
while (i < text.length) {
|
||||
if (text[i] === "<") brackets++;
|
||||
if (text[i] === ">") brackets--;
|
||||
i++;
|
||||
if (!brackets) return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const carriageReturnLineFeed = "\r\n";
|
||||
/**
|
||||
* The default is CRLF.
|
||||
|
||||
Reference in New Issue
Block a user