fix(jsdoc): use the correct scope for exported classes with constructors

Previously, if a module exported an ES2015 class, and the class had a constructor, the generated docs claimed that the class was in the `inner` scope. But `inner` means that the class is _not_ exported.

This issue occurred because we generate separate doclets for the class declaration and constructor. When we merged the two, we incorrectly gave priority to properties in the constructor's doclet, rather than the class declaration's doclet. The constructor's doclet uses the `inner` scope; the class declaration's doclet uses the `static` scope.
This commit is contained in:
Jeff Williams 2020-07-04 18:31:08 -07:00
parent f11bc773ee
commit c9270a4fb5
3 changed files with 24 additions and 1 deletions

View File

@ -319,7 +319,7 @@ function makeConstructorFinisher(parser) {
return; return;
} }
combined = combineDoclets(eventDoclet, parentDoclet); combined = combineDoclets(parentDoclet, eventDoclet);
combined.longname = parentDoclet.longname; combined.longname = parentDoclet.longname;
if (parentDoclet.memberof) { if (parentDoclet.memberof) {
combined.memberof = parentDoclet.memberof; combined.memberof = parentDoclet.memberof;

View File

@ -0,0 +1,13 @@
/** @module foo */
/**
* Bar class.
*
* @alias module:foo.Bar
*/
class Bar {
/** Create a Bar. */
constructor() {}
}
exports.Bar = Bar;

View File

@ -106,4 +106,14 @@ describe('aliases', () => {
expect(method).toBeArrayOfSize(1); expect(method).toBeArrayOfSize(1);
}); });
}); });
describe('class with constructor exported from module', () => {
it('When an exported class with a constructor has an alias, the exported class has the correct scope.', () => {
const docSet = jsdoc.getDocSetFromFile('test/fixtures/aliasexports.js');
const klass = docSet.getByLongname('module:foo.Bar').filter(d => !d.undocumented);
expect(klass).toBeArrayOfSize(1);
expect(klass[0].scope).toBe('static');
});
});
}); });