don't ignore properties like examples on ES2015 class constructors (#1129)

This commit is contained in:
Jeff Williams 2017-07-15 16:03:13 -07:00
parent b28379e398
commit cc66657512
8 changed files with 41 additions and 21 deletions

View File

@ -312,6 +312,7 @@ function makeDefaultParamFinisher() {
*/
function makeConstructorFinisher(parser) {
return function(e) {
var combined;
var doclet = e.doclet;
var parentDoclet;
@ -330,17 +331,15 @@ function makeConstructorFinisher(parser) {
return;
}
if (!parentDoclet.description && doclet.description) {
parentDoclet.description = doclet.description;
}
if ( (!parentDoclet.params || !parentDoclet.params.length) && doclet.params) {
parentDoclet.params = doclet.params.slice(0);
}
if (doclet.hideconstructor) {
parentDoclet.hideconstructor = doclet.hideconstructor;
combined = jsdoc.doclet.combine(doclet, parentDoclet);
combined.longname = parentDoclet.longname;
if (parentDoclet.memberof) {
combined.memberof = parentDoclet.memberof;
}
doclet.undocumented = true;
parser.addResult(combined);
parentDoclet.undocumented = doclet.undocumented = true;
};
}

View File

@ -6,6 +6,8 @@ class Subscription {
* Describe the constructor here.
*
* @param {string} name - The name of the subscription.
* @example
* var subscription = new Subscription();
*/
constructor(name) {}

View File

@ -2,7 +2,9 @@
describe('anonymous class', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/anonymousclass.js');
var klass = docSet.getByLongname('module:test')[2];
var klass = docSet.getByLongname('module:test').filter(function($) {
return !$.undocumented;
})[1];
var foo = docSet.getByLongname('module:test#foo')[0];
var klassTest = docSet.getByLongname('module:test#test')[0];
var klassStaticTest = docSet.getByLongname('module:test.staticTest')[0];

View File

@ -2,7 +2,9 @@
describe('export default class', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/exportdefaultclass.js');
var klass = docSet.getByLongname('module:test')[2];
var klass = docSet.getByLongname('module:test').filter(function($) {
return !$.undocumented;
})[1];
it('should combine the classdesc and constructor description into a single doclet', function() {
expect(klass.classdesc).toBe('Test class');

View File

@ -1,10 +1,14 @@
'use strict';
function filter($) {
return !$.undocumented;
}
describe('module classes', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/moduleclasses.js');
var bar = docSet.getByLongname('module:foo~Bar')[0];
var bar = docSet.getByLongname('module:foo~Bar').filter(filter)[0];
var barBar = docSet.getByLongname('module:foo~Bar#bar')[0];
var baz = docSet.getByLongname('module:foo.Baz')[0];
var baz = docSet.getByLongname('module:foo.Baz').filter(filter)[0];
var bazBaz = docSet.getByLongname('module:foo.Baz#baz')[0];
describe('inner classes', function() {

View File

@ -1,5 +1,9 @@
'use strict';
function filter($) {
return !$.undocumented;
}
describe('@class tag', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/classtag.js');
var ticker = docSet.getByLongname('Ticker')[0];
@ -16,11 +20,12 @@ describe('@class tag', function() {
describe('ES 2015 classes', function() {
var docSet2 = jasmine.getDocSetFromFile('test/fixtures/classtag2.js');
var subscription = docSet2.getByLongname('Subscription')[0];
var subscription = docSet2.getByLongname('Subscription').filter(filter)[0];
var expire = docSet2.getByLongname('Subscription#expire')[0];
var subscriber = docSet2.getByLongname('Subscriber')[0];
var subscriber = docSet2.getByLongname('Subscriber').filter(filter)[0];
var hasCallback = docSet2.getByLongname('Subscriber#hasCallback')[0];
var expiringSubscription = docSet2.getByLongname('subclasses.ExpiringSubscription')[0];
var expiringSubscription = docSet2.getByLongname('subclasses.ExpiringSubscription')
.filter(filter)[0];
var invalidSubscriptionFoo = docSet2.getByLongname('subclasses.InvalidSubscription#foo')[0];
it('When a symbol is a class declaration, the doclet does not require the @class tag', function() {
@ -33,6 +38,8 @@ describe('@class tag', function() {
expect(subscription.description).toBe('Describe the constructor here.');
expect(subscription.params.length).toBe(1);
expect(subscription.params[0].name).toBe('name');
expect(subscription.examples.length).toBe(1);
expect(subscription.examples[0]).toBe('var subscription = new Subscription();');
});
it('When a symbol is a class declaration, its members get the correct longname and memberof', function() {

View File

@ -3,7 +3,9 @@
describe('@hideconstructor tag', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/hideconstructortag.js');
var toaster = docSet.getByLongname('Toaster')[0];
var waffleIron = docSet.getByLongname('WaffleIron')[0];
var waffleIron = docSet.getByLongname('WaffleIron').filter(function($) {
return !$.undocumented;
})[0];
it('should add a `hideconstructor` attribute to pre-ES2015 classes', function() {
expect(toaster.hideconstructor).toBe(true);

View File

@ -1,5 +1,9 @@
'use strict';
function filter($) {
return !$.undocumented;
}
describe('@module tag', function() {
describe("using 'this'", function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/moduletag.js');
@ -19,9 +23,7 @@ describe('@module tag', function() {
describe('misc', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/moduletag2.js');
var mixer = docSet.getByLongname('module:color/mixer').filter(function($) {
return !($.undocumented);
})[0];
var mixer = docSet.getByLongname('module:color/mixer').filter(filter)[0];
var blend = docSet.getByLongname('module:color/mixer.blend')[0];
var darken = docSet.getByLongname('module:color/mixer.darken')[0];
@ -163,7 +165,7 @@ describe('@module tag', function() {
describe('that export a class', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/moduletag11.js');
var foo = docSet.getByLongname('module:foo.Foo')[0];
var foo = docSet.getByLongname('module:foo.Foo').filter(filter)[0];
var testMethod = docSet.getByLongname('module:foo.Foo#testMethod')[0];
it('should identify the correct scope for the exported class', function() {