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

Most doclet properties on ES2015 constructors are ignored #1129

Closed
75lb opened this issue Dec 17, 2015 · 5 comments
Closed

Most doclet properties on ES2015 constructors are ignored #1129

75lb opened this issue Dec 17, 2015 · 5 comments
Labels
Milestone

Comments

@75lb
Copy link

75lb commented Dec 17, 2015

hi.. here's some output from a simple ES6 class..notice the second class record (the constructor) shows undocumented: true despite being documented..

  {
    "comment": "/**\n * a global class\n */",
    "meta": {
      "range": [
        26,
        385
      ],
      "filename": "es6-class.js",
      "lineno": 4,
      "path": "/Users/lloyd/Documents/75lb/testbed/input/global",
      "code": {
        "id": "astnode100000001",
        "name": "GlobalClass",
        "type": "ClassDeclaration",
        "paramnames": [
          "one",
          "two"
        ]
      }
    },
    "classdesc": "a global class",
    "name": "GlobalClass",
    "longname": "GlobalClass",
    "kind": "class",
    "scope": "global",
    "description": "the global class constructor",
    "params": [
      {
        "type": {
          "names": [
            "number"
          ]
        },
        "description": "first param",
        "name": "one"
      },
      {
        "type": {
          "names": [
            "string"
          ]
        },
        "description": "second param",
        "name": "two"
      }
    ]
  },
  {
    "comment": "/**\n   * the global class constructor\n   * @param {number} - first param\n   * @param {string} - second param\n   */",
    "meta": {
      "range": [
        165,
        246
      ],
      "filename": "es6-class.js",
      "lineno": 10,
      "path": "/Users/lloyd/Documents/75lb/testbed/input/global",
      "code": {
        "id": "astnode100000004",
        "name": "GlobalClass",
        "type": "MethodDefinition",
        "paramnames": [
          "one",
          "two"
        ]
      },
      "vars": {
        "": null
      }
    },
    "description": "the global class constructor",
    "params": [
      {
        "type": {
          "names": [
            "number"
          ]
        },
        "description": "first param",
        "name": "one"
      },
      {
        "type": {
          "names": [
            "string"
          ]
        },
        "description": "second param",
        "name": "two"
      }
    ],
    "name": "GlobalClass",
    "longname": "GlobalClass",
    "kind": "class",
    "scope": "global",
    "undocumented": true
  }
@hegemonic
Copy link
Contributor

This is the intended behavior. For an ES2015 class, JSDoc creates two doclets: one for the class declaration, and another for the constructor. JSDoc then merges the second doclet into the first, so the second doclet is no longer needed. (We have to merge the doclets to prevent the class from being documented twice.)

@75lb
Copy link
Author

75lb commented Dec 18, 2015

i had a look at the code, it seems only description and params are merged over - the exceptions are not.. (any @throw, @examples etc docs on the constructor are lost)

i'm still getting my head round the ES2015 differences.. for example, class instance members.. for global ES2015 classes, the instance members are a memberof the class declaration, e.g:

    "longname": "GlobalClass#propOne",
    "kind": "member",
    "memberof": "GlobalClass",

but in a ES2015 class exported from a module, each instance member has a different parent - the constructor..

    "longname": "module:es6-class.ExportedClass#propOne",
    "kind": "member",
    "memberof": "module:es6-class.ExportedClass",

@hegemonic
Copy link
Contributor

i had a look at the code, it seems only description and params are merged over - the exceptions are not.. (any @throw, @examples etc docs on the constructor are lost)

You're right! I wasn't thinking about that when I implemented the feature. I think it's fair to say that this is a bug. I'm reopening this issue to address that bug.

but in a ES2015 class exported from a module, each instance member has a different parent - the constructor..

Can you explain why you think this is wrong? To me, it seems like the exact same (correct) behavior you get with this ES5 code:

/** @module es5-class */

/**
 * Exported class
 * @class
 */
exports.ExportedClass = function() {
    /** propOne */
    this.propOne = '';
};

@hegemonic hegemonic reopened this Dec 21, 2015
@hegemonic hegemonic changed the title es6 constructor is marked 'undocumented' whether it's documented or not Most doclet properties on ES2015 constructors are ignored Dec 21, 2015
@hegemonic hegemonic added this to the 3.4.x milestone Dec 21, 2015
@75lb
Copy link
Author

75lb commented Jan 1, 2016

Can you explain why you think this is wrong? To me, it seems like the exact same (correct) behavior you get with this ES5 code:

interesting, yes i now see that a directly exported ES5 class behaves the same way.. the direct exports.something = function () {} usage is fairly uncommon, which is possibly why i didn't spot this.. it's more commonly

/** 
 * @module example 
 */
exports.something = something

/**
 * @alias module:example
 */
function something () {}

@hegemonic
Copy link
Contributor

Fixed on master. The fix will be included in JSDoc 3.6.0.

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