Skip to content

Commit 75342d8

Browse files
authored
fix(58584): formatJSDocLink shouldn't introduce a trailing space when non link text. (#58585)
1 parent cd40d26 commit 75342d8

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/compiler/utilitiesPublic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ function formatJSDocLink(link: JSDocLink | JSDocLinkCode | JSDocLinkPlain) {
12531253
: link.kind === SyntaxKind.JSDocLinkCode ? "linkcode"
12541254
: "linkplain";
12551255
const name = link.name ? entityNameToString(link.name) : "";
1256-
const space = link.name && link.text.startsWith("://") ? "" : " ";
1256+
const space = link.name && (link.text === "" || link.text.startsWith("://")) ? "" : " ";
12571257
return `{@${kind} ${name}${space}${link.text}}`;
12581258
}
12591259

src/testRunner/unittests/jsDocParsing.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,4 +560,22 @@ class Foo {};
560560
assert.equal(ts.getTextOfJSDocComment(seeTag.comment), "{@link foo#bar label}");
561561
});
562562
});
563+
564+
describe("getTextOfJSDocComment", () => {
565+
it("should preserve link without introducing space", () => {
566+
const sourceText = `
567+
/**
568+
*
569+
* @see {@link foo}
570+
*/
571+
class Foo {};
572+
`;
573+
574+
const root = ts.createSourceFile("foo.ts", sourceText, ts.ScriptTarget.ES5, /*setParentNodes*/ true);
575+
const [classDecl] = root.statements;
576+
const [seeTag] = ts.getJSDocTags(classDecl);
577+
578+
assert.equal(ts.getTextOfJSDocComment(seeTag.comment), "{@link foo}");
579+
});
580+
});
563581
});

tests/baselines/reference/linkTagEmit1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ declare var see3: boolean;
6363
type N = number;
6464
type D1 = {
6565
/**
66-
* Just link to {@link NS.R } this time
66+
* Just link to {@link NS.R} this time
6767
*/
6868
e: 1;
6969
/**

0 commit comments

Comments
 (0)