diff --git a/lib/jsdoc/src/visitor.js b/lib/jsdoc/src/visitor.js index 9ec169b3..3b82a979 100644 --- a/lib/jsdoc/src/visitor.js +++ b/lib/jsdoc/src/visitor.js @@ -158,7 +158,7 @@ function makeRestParamFinisher(parser) { } documentedParams = doclet.params = doclet.params || []; - restNode = findRestParam(e.code.node.params); + restNode = findRestParam(e.code.node.params || e.code.node.value.params); if (restNode) { for (var i = documentedParams.length - 1; i >= 0; i--) { @@ -222,8 +222,8 @@ function makeDefaultParamFinisher(parser) { } documentedParams = doclet.params = doclet.params || []; - params = e.code.node.params; - defaultValues = findDefaultParams(e.code.node.params); + params = e.code.node.params || e.code.node.value.params; + defaultValues = findDefaultParams(params); for (var i = 0, j = 0, l = params.length; i < l; i++) { // bail out if we ran out of documented params @@ -622,9 +622,15 @@ Visitor.prototype.makeSymbolFoundEvent = function(node, parser, filename) { // like: foo() {} // or: constructor() {} case Syntax.MethodDefinition: + extras.finishers = [ + // handle cases where at least one parameter has a default value + makeDefaultParamFinisher(parser), + // handle rest parameters + makeRestParamFinisher(parser) + ]; // for constructors, we attempt to merge the constructor's docs into the class's docs if (node.kind === 'constructor') { - extras.finishers = [makeConstructorFinisher(parser)]; + extras.finishers.push( makeConstructorFinisher(parser) ); } e = new SymbolFound(node, filename, extras); diff --git a/test/fixtures/defaultparams2.js b/test/fixtures/defaultparams2.js new file mode 100644 index 00000000..f8efb7e8 --- /dev/null +++ b/test/fixtures/defaultparams2.js @@ -0,0 +1,10 @@ +'use strict'; + +/** Class representing pizza toppings. */ +class PizzaToppings { + /** + * Set whether sardines are included in the pizza toppings. + * @param {boolean} [bool] `true` to include sardines, `false` to omit them. + */ + setSardines(bool = true) {} +} diff --git a/test/fixtures/restparams2.js b/test/fixtures/restparams2.js new file mode 100644 index 00000000..3eb2c5ac --- /dev/null +++ b/test/fixtures/restparams2.js @@ -0,0 +1,11 @@ +'use strict'; + +/** Class representing a widget. */ +class Widget { + /** + * Add users who can access the widget. + * + * @param {User} users - The users who can access the widget. + */ + addUsers(...users) {} +} diff --git a/test/specs/documentation/defaultparams.js b/test/specs/documentation/defaultparams.js index f13d4c70..133d56fd 100644 --- a/test/specs/documentation/defaultparams.js +++ b/test/specs/documentation/defaultparams.js @@ -49,4 +49,14 @@ describe('default parameters', function() { it('should ignore non-literal default values, such as variable identifiers', function() { expect(setPizzaToppings.params[0].defaultvalue).toBeUndefined(); }); + + describe('ES2015 methods', function() { + var docSet2 = jasmine.getDocSetFromFile('test/fixtures/defaultparams2.js'); + + var setSardines = docSet2.getByLongname('PizzaToppings#setSardines')[0]; + + it('should autodetect default parameters', function() { + expect(setSardines.params[0].defaultvalue).toBe(true); + }); + }); }); diff --git a/test/specs/documentation/restparams.js b/test/specs/documentation/restparams.js index bf30079b..fc4ed6d0 100644 --- a/test/specs/documentation/restparams.js +++ b/test/specs/documentation/restparams.js @@ -18,4 +18,14 @@ describe('rest parameters', function() { expect(restParam.name).toBe('users'); expect(restParam.variable).toBe(true); }); + + describe('ES2015 methods', function() { + var docSet2 = jasmine.getDocSetFromFile('test/fixtures/restparams2.js'); + + var addUsers = docSet2.getByLongname('Widget#addUsers')[0]; + + it('should autodetect rest parameters', function() { + expect(addUsers.params[0].variable).toBe(true); + }); + }); });