mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-25 14:26:29 +00:00
* 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
118 lines
2.5 KiB
JavaScript
118 lines
2.5 KiB
JavaScript
'use strict';
|
|
|
|
var test = require('tap').test;
|
|
var nestTag = require('../../lib/nest').nestTag;
|
|
|
|
// Print a tree of tags in a way that's easy to test.
|
|
var printTree = indent =>
|
|
node =>
|
|
`${new Array(indent + 1).join(' ')}- ${node.name}${node.properties ? '\n' : ''}${(node.properties || [
|
|
])
|
|
.map(printTree(indent + 1))
|
|
.join('\n')}`;
|
|
|
|
var printNesting = params =>
|
|
printTree(0)({ properties: nestTag(params), name: 'root' });
|
|
|
|
test('nest params - basic', function(t) {
|
|
var params = [
|
|
'foo',
|
|
'foo.bar',
|
|
'foo.bar.third',
|
|
'foo.third',
|
|
'foo.third[].baz'
|
|
].map(name => ({ name }));
|
|
t.equal(
|
|
printNesting(params),
|
|
`- root
|
|
- foo
|
|
- foo.bar
|
|
- foo.bar.third
|
|
- foo.third
|
|
- foo.third[].baz`
|
|
);
|
|
t.end();
|
|
});
|
|
|
|
test('nest params - multiple roots', function(t) {
|
|
var params = ['a', 'b', 'c'].map(name => ({ name }));
|
|
t.equal(
|
|
printNesting(params),
|
|
`- root
|
|
- a
|
|
- b
|
|
- c`
|
|
);
|
|
t.end();
|
|
});
|
|
|
|
test('nest params - missing parent', function(t) {
|
|
var params = ['foo', 'foo.bar.third'].map(name => ({ name }));
|
|
t.throws(() => {
|
|
nestTag(params);
|
|
});
|
|
t.end();
|
|
});
|
|
|
|
test('nest params - #658', function(t) {
|
|
var params = [
|
|
'state',
|
|
'payload',
|
|
'payload.input_meter_levels',
|
|
'payload.input_meter_levels[].peak',
|
|
'payload.input_meter_levels[].rms',
|
|
'payload.output_meter_levels',
|
|
'payload.output_meter_levels[].peak',
|
|
'payload.output_meter_levels[].rms'
|
|
].map(name => ({ name }));
|
|
t.equal(
|
|
printNesting(params),
|
|
`- root
|
|
- state
|
|
- payload
|
|
- payload.input_meter_levels
|
|
- payload.input_meter_levels[].peak
|
|
- payload.input_meter_levels[].rms
|
|
- payload.output_meter_levels
|
|
- payload.output_meter_levels[].peak
|
|
- payload.output_meter_levels[].rms`
|
|
);
|
|
t.end();
|
|
});
|
|
|
|
test('nest params - #554', function(t) {
|
|
var params = [
|
|
'x',
|
|
'yIn',
|
|
'options',
|
|
'options.sgOption',
|
|
'options.minMaxRatio',
|
|
'options.broadRatio',
|
|
'options.noiseLevel',
|
|
'options.maxCriteria',
|
|
'options.smoothY',
|
|
'options.realTopDetection',
|
|
'options.heightFactor',
|
|
'options.boundaries',
|
|
'options.derivativeThreshold'
|
|
].map(name => ({ name }));
|
|
t.equal(
|
|
printNesting(params),
|
|
`- root
|
|
- x
|
|
- yIn
|
|
- options
|
|
- options.sgOption
|
|
- options.minMaxRatio
|
|
- options.broadRatio
|
|
- options.noiseLevel
|
|
- options.maxCriteria
|
|
- options.smoothY
|
|
- options.realTopDetection
|
|
- options.heightFactor
|
|
- options.boundaries
|
|
- options.derivativeThreshold`
|
|
);
|
|
t.end();
|
|
});
|