@link parses trailing <...> as part of linkName (#46450)

Similar to #46428.

Fixes #44818
This commit is contained in:
Nathan Shively-Sanders
2021-10-20 17:01:01 -07:00
committed by GitHub
parent 0d022130be
commit f2e5947935
3 changed files with 261 additions and 4 deletions

View File

@@ -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.