documentation/test/fixture/params.input.js
Tom MacWright 73747306a0 refactor(nest): Better nesting implementation (#732)
* refactor(nest): Better nesting implementation

This nesting implementation uses a proper recursive tree algorithm

Fixes https://github.com/documentationjs/documentation/issues/554

BREAKING CHANGE: referencing inferred destructure params without
renaming them, like $0.x, from JSDoc comments will no longer
work. To reference them, instead add a param tag to name the
destructuring param, and then refer to members of that name.

Before:

```js
/**
 * @param {number} $0.x a member of x
 */
function a({ x }) {}
```

After:

```js
/**
 * @param {Object} options
 * @param {number} options.x a member of x
 */
function a({ x }) {}
```

* Address review comments

* Reduce testing node requirement back down to 4

* Don't output empty properties, reduce diff noise

* Rearrange and document params

* Simplify param inference, update test fixtures. This is focused around Array destructuring: documenting destructured array elements with indices instead of names, because the names are purely internal details

* Use temporary fork to get through blocker
2017-04-21 17:28:53 -04:00

112 lines
2.6 KiB
JavaScript

/**
* This function returns the number one.
* @param {number} b the second param
*/
function addThem(a, b, c, { d, e, f }) {
return a + b + c + d + e + f;
}
/**
* This method has partially inferred params
* @param {Object} options
* @param {String} options.fishes number of kinds of fish
*/
function fishesAndFoxes({ fishes, foxes }) {
return fishes + foxes;
}
/**
* This method has a type in the description and a default in the code
* @param {number} x
*/
function withDefault(x = 2) {
return x;
}
/**
* This is foo's documentation
*/
class Foo {
/**
* The method
* @param {number} x Param to method
*/
method(x) {}
}
/**
* Traditional object
*/
var TraditionalObject = {
/**
* This method should acquire the param x
*/
traditionalMethod: function(x) {
return x;
}
};
/**
* Represents an IPv6 address
*
* This tests our support of optional parameters
* @class Address6
* @param {string} address - An IPv6 address string
* @param {number} [groups=8] - How many octets to parse
* @param {?number} third - A third argument
* @param {Array} [foo=[1]] to properly be parsed
* @example
* var address = new Address6('2001::/32');
*/
function Address6() {}
/**
* Create a GeoJSON data source instance given an options object
*
* This tests our support of nested parameters
* @class GeoJSONSource
* @param {Object} [options] optional options
* @param {Object|string} options.data A GeoJSON data object or URL to it.
* The latter is preferable in case of large GeoJSON files.
* @param {number} [options.maxzoom=14] Maximum zoom to preserve detail at.
* @param {number} [options.buffer] Tile buffer on each side.
* @param {number} [options.tolerance] Simplification tolerance (higher means simpler).
*/
function GeoJSONSource(options) {
this.options = options;
}
/**
* This tests our support for parameters with explicit types but with default
* values specified in code.
*
* @param {number} x an argument
*
* @returns {number} some
*/
export const myfunc = (x = 123) => x;
/**
* This tests our support of JSDoc param tags without type information,
* or any type information we could infer from annotations.
*
* @param address - An IPv6 address string
*/
function foo(address) {
return address;
}
/**
* This tests our support for iterator rest inside an
* iterator destructure (RestElement)
*
* @param {Array} input
* @param {any} input.0 head of iterator
* @param {...any} input.xs body of iterator
*
* @returns {any[]} rotated such that the last element was the first
*/
export function rotate([x, ...xs]) {
return [...xs, x];
}