Skip to content

Commit

Permalink
fix: Allow skipped array arguments in destructuring. Fixes #1247 (#1266)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw authored Jul 22, 2019
1 parent 4d99385 commit f9039e9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
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

0 comments on commit f9039e9

Please sign in to comment.