mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
autodetect défault and repeatable parameters in ES2015 methods (#1144)
This commit is contained in:
parent
3d7004a87d
commit
3dbb94f157
@ -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);
|
||||
|
||||
10
test/fixtures/defaultparams2.js
vendored
Normal file
10
test/fixtures/defaultparams2.js
vendored
Normal file
@ -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) {}
|
||||
}
|
||||
11
test/fixtures/restparams2.js
vendored
Normal file
11
test/fixtures/restparams2.js
vendored
Normal file
@ -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) {}
|
||||
}
|
||||
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user