Skip to content

fix: Allow skipped array arguments in destructuring #1266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions __tests__/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8529,7 +8529,7 @@ have any parameter descriptions.",
"context": Object {
"loc": Object {
"end": Object {
"column": 34,
"column": 36,
"line": 16,
},
"start": Object {
Expand Down Expand Up @@ -8593,7 +8593,7 @@ have any parameter descriptions.",
"errors": Array [],
"examples": Array [
Object {
"description": "destructure([1, 2, 3])",
"description": "destructure([0, 1, 2, 3])",
},
],
"implements": Array [],
Expand Down Expand Up @@ -8623,7 +8623,6 @@ have any parameter descriptions.",
"name": "$0",
"properties": Array [
Object {
"lineNumber": 16,
"name": "$0.0",
"title": "param",
},
Expand All @@ -8637,6 +8636,11 @@ have any parameter descriptions.",
"name": "$0.2",
"title": "param",
},
Object {
"lineNumber": 16,
"name": "$0.3",
"title": "param",
},
],
"title": "param",
"type": Object {
Expand All @@ -8656,7 +8660,7 @@ have any parameter descriptions.",
"sees": Array [],
"tags": Array [
Object {
"description": "destructure([1, 2, 3])",
"description": "destructure([0, 1, 2, 3])",
"lineNumber": 2,
"title": "example",
},
Expand Down Expand Up @@ -11631,11 +11635,12 @@ Similar, but with an array
- \`$0.0\`
- \`$0.1\`
- \`$0.2\`
- \`$0.3\`

### Examples

\`\`\`javascript
destructure([1, 2, 3])
destructure([0, 1, 2, 3])
\`\`\`

## multiply
Expand Down Expand Up @@ -12271,6 +12276,28 @@ have any parameter descriptions.",
],
"type": "listItem",
},
Object {
"children": Array [
Object {
"children": Array [
Object {
"type": "inlineCode",
"value": "$0.3",
},
Object {
"type": "text",
"value": " ",
},
Object {
"type": "text",
"value": " ",
},
],
"type": "paragraph",
},
],
"type": "listItem",
},
],
"ordered": false,
"type": "list",
Expand All @@ -12295,7 +12322,7 @@ have any parameter descriptions.",
Object {
"lang": "javascript",
"type": "code",
"value": "destructure([1, 2, 3])",
"value": "destructure([0, 1, 2, 3])",
},
Object {
"children": Array [
Expand Down
6 changes: 3 additions & 3 deletions __tests__/fixture/es6.input.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function destructure({
/**
* Similar, but with an array
* @example
* destructure([1, 2, 3])
* destructure([0, 1, 2, 3])
*/
function destructure([a, b, c]) {}
function destructure([, a, b, c]) {}

/**
* This function returns the number one.
Expand Down Expand Up @@ -184,6 +184,6 @@ class A {
// nullishCoalescingOperator
let x = a ?? b;
// logicalAssignment
return x &&= b?.b |> String.fromCharCode;
return (x &&= b?.b |> String.fromCharCode);
}
}
5 changes: 4 additions & 1 deletion src/infer/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ function paramToDoc(param, prefix, i) {
const newParam = {
title: 'param',
name: prefix ? prefixedName : param.name,
lineNumber: param.loc.start.line
// A skipped array argument like ([, a]);
// looks like { name: '0', indexed: true }, and thus has no location,
// so we allow location to be undefined here.
lineNumber: param.loc ? param.loc.start.line : undefined
};

// Flow/TS annotations
Expand Down