Skip to content

Commit

Permalink
fix(58584): formatJSDocLink shouldn't introduce a trailing space when…
Browse files Browse the repository at this point in the history
… non link text.

fixes microsoft#58584
  • Loading branch information
JeanMeche committed May 20, 2024
1 parent 79a8514 commit ecc5cf8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 57 deletions.
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}");
});
});
});
112 changes: 56 additions & 56 deletions tests/baselines/reference/linkTagEmit1.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//// [tests/cases/conformance/jsdoc/linkTagEmit1.ts] ////

//// [declarations.d.ts]
//// [tests/cases/conformance/jsdoc/linkTagEmit1.ts] ////

//// [declarations.d.ts]
declare namespace NS {
type R = number
}
//// [linkTagEmit1.js]
}
//// [linkTagEmit1.js]
/** @typedef {number} N */
/**
* @typedef {Object} D1
Expand All @@ -25,54 +25,54 @@ function computeCommonSourceDirectoryOfFilenames(integer) {
var see3 = true

/** @typedef {number} Attempt {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}*/


//// [linkTagEmit1.js]
/** @typedef {number} N */
/**
* @typedef {Object} D1
* @property {1} e Just link to {@link NS.R} this time
* @property {1} m Wyatt Earp loved {@link N integers} I bet.
*/
/** @typedef {number} Z @see N {@link N} */
/**
* @param {number} integer {@link Z}
*/
function computeCommonSourceDirectoryOfFilenames(integer) {
return integer + 1; // pls pls pls
}
/** {@link https://hvad} */
var see3 = true;
/** @typedef {number} Attempt {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}*/


//// [linkTagEmit1.d.ts]
/** @typedef {number} N */
/**
* @typedef {Object} D1
* @property {1} e Just link to {@link NS.R} this time
* @property {1} m Wyatt Earp loved {@link N integers} I bet.
*/
/** @typedef {number} Z @see N {@link N} */
/**
* @param {number} integer {@link Z}
*/
declare function computeCommonSourceDirectoryOfFilenames(integer: number): number;
/** {@link https://hvad} */
declare var see3: boolean;
type N = number;
type D1 = {
/**
* Just link to {@link NS.R } this time
*/
e: 1;
/**
* Wyatt Earp loved {@link N integers} I bet.
*/
m: 1;
};
type Z = number;
/**
* {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}
*/
type Attempt = number;


//// [linkTagEmit1.js]
/** @typedef {number} N */
/**
* @typedef {Object} D1
* @property {1} e Just link to {@link NS.R} this time
* @property {1} m Wyatt Earp loved {@link N integers} I bet.
*/
/** @typedef {number} Z @see N {@link N} */
/**
* @param {number} integer {@link Z}
*/
function computeCommonSourceDirectoryOfFilenames(integer) {
return integer + 1; // pls pls pls
}
/** {@link https://hvad} */
var see3 = true;
/** @typedef {number} Attempt {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}*/


//// [linkTagEmit1.d.ts]
/** @typedef {number} N */
/**
* @typedef {Object} D1
* @property {1} e Just link to {@link NS.R} this time
* @property {1} m Wyatt Earp loved {@link N integers} I bet.
*/
/** @typedef {number} Z @see N {@link N} */
/**
* @param {number} integer {@link Z}
*/
declare function computeCommonSourceDirectoryOfFilenames(integer: number): number;
/** {@link https://hvad} */
declare var see3: boolean;
type N = number;
type D1 = {
/**
* Just link to {@link NS.R} this time
*/
e: 1;
/**
* Wyatt Earp loved {@link N integers} I bet.
*/
m: 1;
};
type Z = number;
/**
* {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}
*/
type Attempt = number;

0 comments on commit ecc5cf8

Please sign in to comment.