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

getTextOfJSDocComment is stripping # from JSDoc comment #58259

Closed
JeanMeche opened this issue Apr 19, 2024 · 2 comments Β· Fixed by #58338
Closed

getTextOfJSDocComment is stripping # from JSDoc comment #58259

JeanMeche opened this issue Apr 19, 2024 · 2 comments Β· Fixed by #58338
Labels
Bug A bug in TypeScript

Comments

@JeanMeche
Copy link

JeanMeche commented Apr 19, 2024

πŸ”Ž Search Terms

  • getJSDocTags
  • getTextOfJSDocComment
  • hashtash

πŸ•— Version & Regression Information

Latest, 5.4

⏯ Playground Link

https://stackblitz.com/edit/gettextofjsdoccomment?file=main.ts

πŸ’» Code

Thanks to @RyanCavanaugh's help in #58249, I could finaly land this repro πŸ˜„

import ts from 'typescript';

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

/** 
 * 
 * @see {@link entry#anchor label}
 */
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

Extracted JSDoc comment : {@link entryanchor label}

πŸ™‚ Expected behavior

Extracted JSDoc comment : {@link entry#anchor label}

Additional information about the issue

No response

@RyanCavanaugh
Copy link
Member

I think we need to do this?

/** @internal */
export function entityNameToString(name: EntityNameOrEntityNameExpression | JSDocMemberName | JsxTagNameExpression | PrivateIdentifier): string {
    switch (name.kind) {
        case SyntaxKind.ThisKeyword:
            return "this";
        case SyntaxKind.PrivateIdentifier:
        case SyntaxKind.Identifier:
            return getFullWidth(name) === 0 ? idText(name) : getTextOfNode(name);
        case SyntaxKind.QualifiedName:
            return entityNameToString(name.left) + "." + entityNameToString(name.right);
        case SyntaxKind.PropertyAccessExpression:
            if (isIdentifier(name.name) || isPrivateIdentifier(name.name)) {
                return entityNameToString(name.expression) + "." + entityNameToString(name.name);
            }
            else {
                return Debug.assertNever(name.name);
            }
        case SyntaxKind.JSDocMemberName:
            return entityNameToString(name.left) + "#" + entityNameToString(name.right);
//                                                ^^^^^^
        case SyntaxKind.JsxNamespacedName:
            return entityNameToString(name.namespace) + ":" + entityNameToString(name.name);
        default:
            return Debug.assertNever(name);
    }
}

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Apr 19, 2024
@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels May 1, 2024
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 5.5.1 milestone May 1, 2024
@DanielRosenwasser
Copy link
Member

Thanks @a-tarasyuk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants