Skip to content

Commit 6961ee8

Browse files
hey-leontmcw
authored andcommitted
fix(params): added code path for type RestElement
* FIX: added code path for type RestElement * TEST: integration test for documenting RestElement node
1 parent 191056e commit 6961ee8

File tree

5 files changed

+616
-0
lines changed

5 files changed

+616
-0
lines changed

lib/infer/params.js

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ function paramToDoc(
9696
return paramToDoc(property, comment, i, prefix + '$' + String(i) + '.');
9797
} else if (property.type === 'RestProperty') {
9898
return paramToDoc(property, comment, i, prefix + '$' + String(i) + '.');
99+
} else if (property.type === 'RestElement') {
100+
return paramToDoc(property, comment, i, prefix + '$' + String(i) + '.');
99101
}
100102
throw new Error(`Unknown property encountered: ${property.type}`);
101103
}

test/fixture/params.input.js

+13
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,16 @@ export const myfunc = (x = 123) => x;
9494
function foo(address) {
9595
return address;
9696
}
97+
98+
/**
99+
* This tests our support for iterator rest inside an
100+
* iterator destructure (RestElement)
101+
*
102+
* @param {any} $0.x head of iterator
103+
* @param {any[]} ...$0.xs body of iterator
104+
*
105+
* @returns {any[]} rotated such that the last element was the first
106+
*/
107+
export function rotate([x, ...xs]) {
108+
return [...xs, x];
109+
}

test/fixture/params.output.json

+309
Original file line numberDiff line numberDiff line change
@@ -2461,5 +2461,314 @@
24612461
}
24622462
],
24632463
"namespace": "foo"
2464+
},
2465+
{
2466+
"description": {
2467+
"type": "root",
2468+
"children": [
2469+
{
2470+
"type": "paragraph",
2471+
"children": [
2472+
{
2473+
"type": "text",
2474+
"value": "This tests our support for iterator rest inside an\niterator destructure (RestElement)",
2475+
"position": {
2476+
"start": {
2477+
"line": 1,
2478+
"column": 1,
2479+
"offset": 0
2480+
},
2481+
"end": {
2482+
"line": 2,
2483+
"column": 35,
2484+
"offset": 85
2485+
},
2486+
"indent": [
2487+
1
2488+
]
2489+
}
2490+
}
2491+
],
2492+
"position": {
2493+
"start": {
2494+
"line": 1,
2495+
"column": 1,
2496+
"offset": 0
2497+
},
2498+
"end": {
2499+
"line": 2,
2500+
"column": 35,
2501+
"offset": 85
2502+
},
2503+
"indent": [
2504+
1
2505+
]
2506+
}
2507+
}
2508+
],
2509+
"position": {
2510+
"start": {
2511+
"line": 1,
2512+
"column": 1,
2513+
"offset": 0
2514+
},
2515+
"end": {
2516+
"line": 2,
2517+
"column": 35,
2518+
"offset": 85
2519+
}
2520+
}
2521+
},
2522+
"tags": [
2523+
{
2524+
"title": "param",
2525+
"description": "head of iterator",
2526+
"lineNumber": 4,
2527+
"type": {
2528+
"type": "NameExpression",
2529+
"name": "any"
2530+
},
2531+
"name": "$0.x"
2532+
},
2533+
{
2534+
"title": "param",
2535+
"description": "...$0.xs body of iterator",
2536+
"lineNumber": 5,
2537+
"type": {
2538+
"type": "TypeApplication",
2539+
"expression": {
2540+
"type": "NameExpression",
2541+
"name": "Array"
2542+
},
2543+
"applications": [
2544+
{
2545+
"type": "NameExpression",
2546+
"name": "any"
2547+
}
2548+
]
2549+
},
2550+
"name": null,
2551+
"errors": [
2552+
"Missing or invalid tag name"
2553+
]
2554+
},
2555+
{
2556+
"title": "returns",
2557+
"description": "rotated such that the last element was the first",
2558+
"lineNumber": 7,
2559+
"type": {
2560+
"type": "TypeApplication",
2561+
"expression": {
2562+
"type": "NameExpression",
2563+
"name": "Array"
2564+
},
2565+
"applications": [
2566+
{
2567+
"type": "NameExpression",
2568+
"name": "any"
2569+
}
2570+
]
2571+
}
2572+
}
2573+
],
2574+
"loc": {
2575+
"start": {
2576+
"line": 98,
2577+
"column": 0
2578+
},
2579+
"end": {
2580+
"line": 106,
2581+
"column": 3
2582+
}
2583+
},
2584+
"context": {
2585+
"loc": {
2586+
"start": {
2587+
"line": 107,
2588+
"column": 0
2589+
},
2590+
"end": {
2591+
"line": 109,
2592+
"column": 1
2593+
}
2594+
}
2595+
},
2596+
"augments": [],
2597+
"errors": [
2598+
{
2599+
"message": "Missing or invalid tag name"
2600+
}
2601+
],
2602+
"examples": [],
2603+
"params": [
2604+
{
2605+
"title": "param",
2606+
"name": "$0",
2607+
"type": {
2608+
"type": "AllLiteral"
2609+
},
2610+
"properties": [
2611+
{
2612+
"title": "param",
2613+
"name": "$0.x",
2614+
"lineNumber": 4,
2615+
"description": {
2616+
"type": "root",
2617+
"children": [
2618+
{
2619+
"type": "paragraph",
2620+
"children": [
2621+
{
2622+
"type": "text",
2623+
"value": "head of iterator",
2624+
"position": {
2625+
"start": {
2626+
"line": 1,
2627+
"column": 1,
2628+
"offset": 0
2629+
},
2630+
"end": {
2631+
"line": 1,
2632+
"column": 17,
2633+
"offset": 16
2634+
},
2635+
"indent": []
2636+
}
2637+
}
2638+
],
2639+
"position": {
2640+
"start": {
2641+
"line": 1,
2642+
"column": 1,
2643+
"offset": 0
2644+
},
2645+
"end": {
2646+
"line": 1,
2647+
"column": 17,
2648+
"offset": 16
2649+
},
2650+
"indent": []
2651+
}
2652+
}
2653+
],
2654+
"position": {
2655+
"start": {
2656+
"line": 1,
2657+
"column": 1,
2658+
"offset": 0
2659+
},
2660+
"end": {
2661+
"line": 1,
2662+
"column": 17,
2663+
"offset": 16
2664+
}
2665+
}
2666+
},
2667+
"type": {
2668+
"type": "NameExpression",
2669+
"name": "any"
2670+
}
2671+
},
2672+
{
2673+
"title": "param",
2674+
"name": "$0.xs",
2675+
"lineNumber": 107,
2676+
"type": {
2677+
"type": "RestType"
2678+
}
2679+
}
2680+
]
2681+
}
2682+
],
2683+
"properties": [],
2684+
"returns": [
2685+
{
2686+
"description": {
2687+
"type": "root",
2688+
"children": [
2689+
{
2690+
"type": "paragraph",
2691+
"children": [
2692+
{
2693+
"type": "text",
2694+
"value": "rotated such that the last element was the first",
2695+
"position": {
2696+
"start": {
2697+
"line": 1,
2698+
"column": 1,
2699+
"offset": 0
2700+
},
2701+
"end": {
2702+
"line": 1,
2703+
"column": 49,
2704+
"offset": 48
2705+
},
2706+
"indent": []
2707+
}
2708+
}
2709+
],
2710+
"position": {
2711+
"start": {
2712+
"line": 1,
2713+
"column": 1,
2714+
"offset": 0
2715+
},
2716+
"end": {
2717+
"line": 1,
2718+
"column": 49,
2719+
"offset": 48
2720+
},
2721+
"indent": []
2722+
}
2723+
}
2724+
],
2725+
"position": {
2726+
"start": {
2727+
"line": 1,
2728+
"column": 1,
2729+
"offset": 0
2730+
},
2731+
"end": {
2732+
"line": 1,
2733+
"column": 49,
2734+
"offset": 48
2735+
}
2736+
}
2737+
},
2738+
"title": "returns",
2739+
"type": {
2740+
"type": "TypeApplication",
2741+
"expression": {
2742+
"type": "NameExpression",
2743+
"name": "Array"
2744+
},
2745+
"applications": [
2746+
{
2747+
"type": "NameExpression",
2748+
"name": "any"
2749+
}
2750+
]
2751+
}
2752+
}
2753+
],
2754+
"sees": [],
2755+
"throws": [],
2756+
"todos": [],
2757+
"name": "rotate",
2758+
"kind": "function",
2759+
"members": {
2760+
"global": [],
2761+
"inner": [],
2762+
"instance": [],
2763+
"events": [],
2764+
"static": []
2765+
},
2766+
"path": [
2767+
{
2768+
"name": "rotate",
2769+
"kind": "function"
2770+
}
2771+
],
2772+
"namespace": "rotate"
24642773
}
24652774
]

test/fixture/params.output.md

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- [GeoJSONSource](#geojsonsource)
1414
- [myfunc](#myfunc)
1515
- [foo](#foo-1)
16+
- [rotate](#rotate)
1617

1718
## addThem
1819

@@ -123,3 +124,16 @@ or any type information we could infer from annotations.
123124
**Parameters**
124125

125126
- `address` An IPv6 address string
127+
128+
## rotate
129+
130+
This tests our support for iterator rest inside an
131+
iterator destructure (RestElement)
132+
133+
**Parameters**
134+
135+
- `$0` **any**
136+
- `$0.x` **any** head of iterator
137+
- `$0.xs` **...any**
138+
139+
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<any>** rotated such that the last element was the first

0 commit comments

Comments
 (0)