Skip to content

Comments lost in variable declarations #570

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

Closed
pago opened this issue Oct 15, 2016 · 1 comment
Closed

Comments lost in variable declarations #570

pago opened this issue Oct 15, 2016 · 1 comment
Assignees

Comments

@pago
Copy link
Contributor

pago commented Oct 15, 2016

In #544 support for patterns like

/**
 * Does foo!
 */
var foo = function() {};

export { foo }

has been added. However, the comment is lost and does not appear in the generated documentation.

I've tried to add it by adjusting addComments within lib/extractors/exported.js to the following:

function getComments(data, path) {
    if (!hasJSDocComment(path)) {
      if (t.isVariableDeclarator(path.parentPath.node)) {
        return getComments(data, path.parentPath);
      }
      if (t.isVariableDeclaration(path.parentPath.node) && path.parentPath.node.declarations.length === 1) {
        return getComments(data, path.parentPath);
      }
      var result = addBlankComment(data, path, path.node);
      return result ? [result] : [];
    }
    return path.node.leadingComments.filter(isJSDocComment).map(function (comment) {
      return addComment(data, comment.value, comment.loc, path, path.node.loc, true);
    }).filter(Boolean);
  }

which worked (in some cases) but also resulted in some duplicated documentation. Any hint on how to implement this?

@arv arv self-assigned this Oct 17, 2016
@arv
Copy link
Contributor

arv commented Oct 19, 2016

Here is what happens... The binding for foo is a VariableDeclarator but the comment is attached to the VariableDeclaration. We need to find the comment on the parent path.

Patch is on its way.

arv added a commit to arv/documentation that referenced this issue Oct 19, 2016
When we find the binding for an export we get the VariableDeclarator.
It is common for people to write their JSDoc comment on the parent
VariableDeclaration so we check that in case there is no comment on the
declarator.

Fixes documentationjs#570
@arv arv closed this as completed in #571 Oct 21, 2016
arv added a commit that referenced this issue Oct 21, 2016
When we find the binding for an export we get the VariableDeclarator.
It is common for people to write their JSDoc comment on the parent
VariableDeclaration so we check that in case there is no comment on the
declarator.

Fixes #570
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