Skip to content

getTextOfJSDocComment introduces a space in JSDoc comments #58584

@JeanMeche

Description

@JeanMeche

🔎 Search Terms

getJSDocTags
getTextOfJSDocComment

🕗 Version & Regression Information

5.5.0-beta and previous.

⏯ Playground Link

https://stackblitz.com/edit/gettextofjsdoccomment-dbm6rj?file=main.ts,package.json

💻 Code

import ts from 'typescript';

const filename = 'example.ts';
const code = `

/** 
 * 
 * @see {@link entry}
 */
class Foo  {};
`;

const sourceFile = ts.createSourceFile(
  filename,
  code,
  ts.ScriptTarget.ESNext,
  true
);

const visitNode = (node: ts.Node) => {
  ts.forEachChild(node, visitNode);
  const tags = ts.getJSDocTags(node);
  if (tags.length) {
    tags.forEach((tag) => {
      console.log('> ', ts.getTextOfJSDocComment(tag.comment));
    });
  }
};

ts.forEachChild(sourceFile, visitNode);

🙁 Actual behavior

getTextOfJSDocComment returns {@link entry }. Notice the trailing space.

🙂 Expected behavior

getTextOfJSDocComment should return {@link entry}, without introducing a space.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions