correctly document constructors and instance properties of ES2015 classes (#1182)

This commit is contained in:
Jeff Williams 2017-07-07 10:54:55 -07:00
parent 67db938c0b
commit 0e4f1a9575
3 changed files with 55 additions and 0 deletions

View File

@ -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;

19
test/fixtures/moduleclasses.js vendored Normal file
View File

@ -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;
}
}

View File

@ -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');
});
});
});