Skip to content

Commit f9039e9

Browse files
authored
fix: Allow skipped array arguments in destructuring. Fixes #1247 (#1266)
1 parent 4d99385 commit f9039e9

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

__tests__/__snapshots__/test.js.snap

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8529,7 +8529,7 @@ have any parameter descriptions.",
85298529
"context": Object {
85308530
"loc": Object {
85318531
"end": Object {
8532-
"column": 34,
8532+
"column": 36,
85338533
"line": 16,
85348534
},
85358535
"start": Object {
@@ -8593,7 +8593,7 @@ have any parameter descriptions.",
85938593
"errors": Array [],
85948594
"examples": Array [
85958595
Object {
8596-
"description": "destructure([1, 2, 3])",
8596+
"description": "destructure([0, 1, 2, 3])",
85978597
},
85988598
],
85998599
"implements": Array [],
@@ -8623,7 +8623,6 @@ have any parameter descriptions.",
86238623
"name": "$0",
86248624
"properties": Array [
86258625
Object {
8626-
"lineNumber": 16,
86278626
"name": "$0.0",
86288627
"title": "param",
86298628
},
@@ -8637,6 +8636,11 @@ have any parameter descriptions.",
86378636
"name": "$0.2",
86388637
"title": "param",
86398638
},
8639+
Object {
8640+
"lineNumber": 16,
8641+
"name": "$0.3",
8642+
"title": "param",
8643+
},
86408644
],
86418645
"title": "param",
86428646
"type": Object {
@@ -8656,7 +8660,7 @@ have any parameter descriptions.",
86568660
"sees": Array [],
86578661
"tags": Array [
86588662
Object {
8659-
"description": "destructure([1, 2, 3])",
8663+
"description": "destructure([0, 1, 2, 3])",
86608664
"lineNumber": 2,
86618665
"title": "example",
86628666
},
@@ -11631,11 +11635,12 @@ Similar, but with an array
1163111635
- \`$0.0\`
1163211636
- \`$0.1\`
1163311637
- \`$0.2\`
11638+
- \`$0.3\`
1163411639

1163511640
### Examples
1163611641

1163711642
\`\`\`javascript
11638-
destructure([1, 2, 3])
11643+
destructure([0, 1, 2, 3])
1163911644
\`\`\`
1164011645

1164111646
## multiply
@@ -12271,6 +12276,28 @@ have any parameter descriptions.",
1227112276
],
1227212277
"type": "listItem",
1227312278
},
12279+
Object {
12280+
"children": Array [
12281+
Object {
12282+
"children": Array [
12283+
Object {
12284+
"type": "inlineCode",
12285+
"value": "$0.3",
12286+
},
12287+
Object {
12288+
"type": "text",
12289+
"value": " ",
12290+
},
12291+
Object {
12292+
"type": "text",
12293+
"value": " ",
12294+
},
12295+
],
12296+
"type": "paragraph",
12297+
},
12298+
],
12299+
"type": "listItem",
12300+
},
1227412301
],
1227512302
"ordered": false,
1227612303
"type": "list",
@@ -12295,7 +12322,7 @@ have any parameter descriptions.",
1229512322
Object {
1229612323
"lang": "javascript",
1229712324
"type": "code",
12298-
"value": "destructure([1, 2, 3])",
12325+
"value": "destructure([0, 1, 2, 3])",
1229912326
},
1230012327
Object {
1230112328
"children": Array [

__tests__/fixture/es6.input.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ function destructure({
1111
/**
1212
* Similar, but with an array
1313
* @example
14-
* destructure([1, 2, 3])
14+
* destructure([0, 1, 2, 3])
1515
*/
16-
function destructure([a, b, c]) {}
16+
function destructure([, a, b, c]) {}
1717

1818
/**
1919
* This function returns the number one.
@@ -184,6 +184,6 @@ class A {
184184
// nullishCoalescingOperator
185185
let x = a ?? b;
186186
// logicalAssignment
187-
return x &&= b?.b |> String.fromCharCode;
187+
return (x &&= b?.b |> String.fromCharCode);
188188
}
189189
}

src/infer/params.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,10 @@ function paramToDoc(param, prefix, i) {
273273
const newParam = {
274274
title: 'param',
275275
name: prefix ? prefixedName : param.name,
276-
lineNumber: param.loc.start.line
276+
// A skipped array argument like ([, a]);
277+
// looks like { name: '0', indexed: true }, and thus has no location,
278+
// so we allow location to be undefined here.
279+
lineNumber: param.loc ? param.loc.start.line : undefined
277280
};
278281

279282
// Flow/TS annotations

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy