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

View File

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

View File

@ -2,7 +2,9 @@
describe('anonymous class', function() { describe('anonymous class', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/anonymousclass.js'); 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 foo = docSet.getByLongname('module:test#foo')[0];
var klassTest = docSet.getByLongname('module:test#test')[0]; var klassTest = docSet.getByLongname('module:test#test')[0];
var klassStaticTest = docSet.getByLongname('module:test.staticTest')[0]; var klassStaticTest = docSet.getByLongname('module:test.staticTest')[0];

View File

@ -2,7 +2,9 @@
describe('export default class', function() { describe('export default class', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/exportdefaultclass.js'); 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() { it('should combine the classdesc and constructor description into a single doclet', function() {
expect(klass.classdesc).toBe('Test class'); expect(klass.classdesc).toBe('Test class');

View File

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

View File

@ -1,5 +1,9 @@
'use strict'; 'use strict';
function filter($) {
return !$.undocumented;
}
describe('@class tag', function() { describe('@class tag', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/classtag.js'); var docSet = jasmine.getDocSetFromFile('test/fixtures/classtag.js');
var ticker = docSet.getByLongname('Ticker')[0]; var ticker = docSet.getByLongname('Ticker')[0];
@ -16,11 +20,12 @@ describe('@class tag', function() {
describe('ES 2015 classes', function() { describe('ES 2015 classes', function() {
var docSet2 = jasmine.getDocSetFromFile('test/fixtures/classtag2.js'); 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 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 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]; 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() { 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.description).toBe('Describe the constructor here.');
expect(subscription.params.length).toBe(1); expect(subscription.params.length).toBe(1);
expect(subscription.params[0].name).toBe('name'); 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() { 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() { describe('@hideconstructor tag', function() {
var docSet = jasmine.getDocSetFromFile('test/fixtures/hideconstructortag.js'); var docSet = jasmine.getDocSetFromFile('test/fixtures/hideconstructortag.js');
var toaster = docSet.getByLongname('Toaster')[0]; 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() { it('should add a `hideconstructor` attribute to pre-ES2015 classes', function() {
expect(toaster.hideconstructor).toBe(true); expect(toaster.hideconstructor).toBe(true);

View File

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