Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(58584): formatJSDocLink shouldn't introduce a trailing space when non link text. #58585

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/utilitiesPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ function formatJSDocLink(link: JSDocLink | JSDocLinkCode | JSDocLinkPlain) {
: link.kind === SyntaxKind.JSDocLinkCode ? "linkcode"
: "linkplain";
const name = link.name ? entityNameToString(link.name) : "";
const space = link.name && link.text.startsWith("://") ? "" : " ";
const space = link.name && (link.text === "" || link.text.startsWith("://")) ? "" : " ";
return `{@${kind} ${name}${space}${link.text}}`;
}

Expand Down
18 changes: 18 additions & 0 deletions src/testRunner/unittests/jsDocParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,22 @@ class Foo {};
assert.equal(ts.getTextOfJSDocComment(seeTag.comment), "{@link foo#bar label}");
});
});

describe("getTextOfJSDocComment", () => {
it("should preserve link without introducing space", () => {
const sourceText = `
/**
*
* @see {@link foo}
*/
class Foo {};
`;

const root = ts.createSourceFile("foo.ts", sourceText, ts.ScriptTarget.ES5, /*setParentNodes*/ true);
const [classDecl] = root.statements;
const [seeTag] = ts.getJSDocTags(classDecl);

assert.equal(ts.getTextOfJSDocComment(seeTag.comment), "{@link foo}");
});
});
});
2 changes: 1 addition & 1 deletion tests/baselines/reference/linkTagEmit1.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ declare var see3: boolean;
type N = number;
type D1 = {
/**
* Just link to {@link NS.R } this time
* Just link to {@link NS.R} this time
*/
e: 1;
/**
Expand Down