Skip to content

Commit

Permalink
correctly document constructors and instance properties of ES2015 cla…
Browse files Browse the repository at this point in the history
…sses (#1182)
  • Loading branch information
hegemonic committed Jul 7, 2017
1 parent 67db938 commit 0e4f1a9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/jsdoc/src/parser.js
Expand Up @@ -359,6 +359,11 @@ Parser.prototype.astnodeToMemberof = function(node) {

result.memberof = doclet.longname + jsdoc.name.SCOPE.PUNC.INSTANCE;
}
else if (type === Syntax.MethodDefinition && node.kind === 'constructor') {
doclet = this._getDocletById(node.enclosingScope.nodeId);

result.memberof = doclet.memberof + jsdoc.name.SCOPE.PUNC.INNER;
}
else {
// check local references for aliases
scope = node;
Expand Down
19 changes: 19 additions & 0 deletions test/fixtures/moduleclasses.js
@@ -0,0 +1,19 @@
/** @module foo */

/** Bar class. */
class Bar {
/** Construct a Bar. */
constructor() {
/** bar property */
this.bar = 0;
}
}

/** Baz class. */
export class Baz {
/** Construct a Baz. */
constructor() {
/** baz property */
this.baz = 0;
}
}
31 changes: 31 additions & 0 deletions test/specs/documentation/moduleclasses.js
@@ -0,0 +1,31 @@
'use strict';

describe('module classes', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/moduleclasses.js');
var bar = docSet.getByLongname('module:foo~Bar')[0];
var barBar = docSet.getByLongname('module:foo~Bar#bar')[0];
var baz = docSet.getByLongname('module:foo.Baz')[0];
var bazBaz = docSet.getByLongname('module:foo.Baz#baz')[0];

describe('inner classes', function() {
it('should merge the constructor doclet with the class doclet', function() {
expect(bar.description).toBe('Construct a Bar.');
expect(bar.classdesc).toBe('Bar class.');
});

it('should correctly mark the scope of instance properties', function() {
expect(barBar.scope).toBe('instance');
});
});

describe('exported classes', function() {
it('should merge the constructor doclet with the class doclet', function() {
expect(baz.description).toBe('Construct a Baz.');
expect(baz.classdesc).toBe('Baz class.');
});

it('should correctly mark the scope of instance properties', function() {
expect(bazBaz.scope).toBe('instance');
});
});
});

0 comments on commit 0e4f1a9

Please sign in to comment.