Skip to content

Properties defined inside constructor function are not documented as class members #556

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
chkt opened this issue Sep 26, 2016 · 3 comments
Labels

Comments

@chkt
Copy link
Contributor

chkt commented Sep 26, 2016

First thanks to everybody working on this. This has great potential to become the very best javascript documentation generator out there.

When I define properties on this inside the constructor of a class, they get documented a properties of the global object.

/**
 * Does nothing
 */
export default class Foo {

    /**
     * Creates a new instance
     * @param {string} str
     */
    constructor(str) {
        /**
         * A useless property
         * @memberof Foo
         * @type {string}
         */
        this.bar = "";
    }

    ...
}

Removing @memberof does not change anything, the new property is still documented as belonging to the global scope.

@chkt
Copy link
Contributor Author

chkt commented Sep 29, 2016

So I did some digging and it turns out the problem lies in lib/infer/membership.js, where extractIdentifiers will only resolve membership chains like a.b.c, but not membership chains like this.a.

Changing path.traverse to also watch out for the ThisExpression fixed it for my use case.

path.traverse({
    ThisExpression : function (path) {
      if (n.isClassMethod(path.scope.block)) {
        identifiers.push(path.scope.path.parentPath.parentPath.node.id.name, 'prototype');
      }
    },

    /**
     * Add an identifier in a path to the identifiers array
     * @param {Object} path ast path
     * @returns {undefined} has side-effects
     * @private
     */
    Identifier: function (path) {
      identifiers.push(path.node.name);
    }
  });

This is obviously not exhaustive. I am at a loss if this is even the place where this should be handled and if it is, which way forward would be optimal within the given architectural framework.

Since this is not covered at all right now, I am also wondering what should be the minimal requirements for a membership inference with this.

@chkt
Copy link
Contributor Author

chkt commented Oct 5, 2016

Added pull request

@tmcw tmcw added the bug label Nov 23, 2016
@tmcw
Copy link
Member

tmcw commented Nov 23, 2016

PR is merged! I'm going to close this issue out by adding the above code example to a test fixture.

@tmcw tmcw closed this as completed in 5a67282 Nov 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants