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

Question: Why propertyAssignment node don't support getJsDoc method? #1543

Open
mortalYoung opened this issue Jun 19, 2024 · 1 comment
Open

Comments

@mortalYoung
Copy link

I could find JSDoc node from ast. But when I can't get it by getJsDoc.

https://ts-ast-viewer.com/#code/PQKhCgAIUgVALAlgZ0iyAXApsjUTDhYAeADgPYBOGkAxuQHa6Y40C8kA3lJL6BL0EwE6dAEMeQwoMhiAXJACMAGkmR+a6HCSp0AI00E1ehQCZVAXwDc4IA

if (Node.isPropertyAssignment(node)) {
    const jsDoc = node
        .getJsDocs()
        .map((doc) => doc.getCommentText())
        .join('\n'); // throw error about type "PropertyAssignment" don't have method "getJsDocs"。
} 

I don't know it's a feature or bug?

@ryoppippi
Copy link

This works for me

const code = `
/**
 * This is test
 */
export const test = {
    /**
     * This is a
     */
    a: 1,
    /**
     * This is b
     */
    b: 2,
};
`;

const project = new Project();
const sourceFile = project.createSourceFile("", code);

sourceFile.forEachDescendant((node) => {
  if (Node.isVariableStatement(node)) {
    const docs = node.getJsDocs();
    for (const doc of docs) {
      console.log(doc.getCommentText());
    }
  }
});

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

No branches or pull requests

2 participants