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

Can't get JsDocs directly from a VariableDeclaration #16

Closed
JoshuaKGoldberg opened this issue Dec 6, 2017 · 4 comments
Closed

Can't get JsDocs directly from a VariableDeclaration #16

JoshuaKGoldberg opened this issue Dec 6, 2017 · 4 comments
Assignees

Comments

@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Dec 6, 2017

/**
 * First
 */
const firstVariable = true,
    /**
     * Second
     */
    secondVariable = false;
import { getJsDoc } from "tsutils";

// Edit: not visitVariableStatement(node: VariableStatement)
function visitVariableDeclaration(node: VariableDeclaration) {
    // Blank
    getJsDoc(node);

    // Always ["First"]
    getJsDoc(node.parent);
}

Expected:

Calling getJsDoc on a VariableStatement should retrieve the docs for the node, even if they're also the docs for the containing VariableDeclarationList.

Actual:

Only ever gets the docs for the VariableDeclarationList.

@ajafff
Copy link
Owner

ajafff commented Dec 6, 2017

I think you mixed up VariableStatement and VariableDeclarationList in your example.
VariableDeclarationList never has any JSDoc, because it is located on the VariableStatement.

This function is not intended to find the JSDoc on any parent node. It's just a thin wrapper to make the internal property Node.jsDoc available to use in your program.
TypeScript never parses JSDoc on VariableDeclaration or VariableDeclarationList. You need to take care of passing the correct node to the function.

If there is the need for a function that retrieves JSDoc for a node the way TypeScript does, I can probably add that on top.

@JoshuaKGoldberg
Copy link
Contributor Author

Yes and yes. The context is TSLint's completed-docs function.

@JoshuaKGoldberg JoshuaKGoldberg changed the title Can't get JsDocs directly from a VariableStatement Can't get JsDocs directly from a VariableDeclaration Dec 6, 2017
@ajafff ajafff self-assigned this Dec 6, 2017
@ajafff
Copy link
Owner

ajafff commented Dec 6, 2017

@JoshuaKGoldberg what would the ideal API look like?

You throw in any Node / (Named)Declaration and get back the JSDoc TypeScript would use?
Should it automatically search for JSDoc on the opposite property accessor?

@JoshuaKGoldberg
Copy link
Contributor Author

IMO yes, but with the caveat that it only looks at the single file (no class inheritance checks or the like). Other than that get/set edge case, and parsing through variable statement/declaration/declaration lists, I can't think of other edge cases.

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

No branches or pull requests

2 participants