From 5d43aa3d452663ded8f3a70845849d3612e9aef0 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 22 Jul 2019 13:00:32 -0700 Subject: [PATCH] fix: Allow skipped array arguments in destructuring. Fixes #1247 --- __tests__/__snapshots__/test.js.snap | 39 +++++++++++++++++++++++----- __tests__/fixture/es6.input.js | 6 ++--- src/infer/params.js | 5 +++- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/__tests__/__snapshots__/test.js.snap b/__tests__/__snapshots__/test.js.snap index 81879b012..e16e3e75a 100644 --- a/__tests__/__snapshots__/test.js.snap +++ b/__tests__/__snapshots__/test.js.snap @@ -8529,7 +8529,7 @@ have any parameter descriptions.", "context": Object { "loc": Object { "end": Object { - "column": 34, + "column": 36, "line": 16, }, "start": Object { @@ -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 [], @@ -8623,7 +8623,6 @@ have any parameter descriptions.", "name": "$0", "properties": Array [ Object { - "lineNumber": 16, "name": "$0.0", "title": "param", }, @@ -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 { @@ -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", }, @@ -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 @@ -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", @@ -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 [ diff --git a/__tests__/fixture/es6.input.js b/__tests__/fixture/es6.input.js index a300409a2..7e27ec7a4 100644 --- a/__tests__/fixture/es6.input.js +++ b/__tests__/fixture/es6.input.js @@ -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. @@ -184,6 +184,6 @@ class A { // nullishCoalescingOperator let x = a ?? b; // logicalAssignment - return x &&= b?.b |> String.fromCharCode; + return (x &&= b?.b |> String.fromCharCode); } } diff --git a/src/infer/params.js b/src/infer/params.js index dc67c0b81..93a1ae034 100644 --- a/src/infer/params.js +++ b/src/infer/params.js @@ -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 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