grasp
grasp copied to clipboard
Array destructuring - Ignoring some returned values - Error
When I use array destructuring with ignored values, grasp throws error. (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Ignoring_some_returned_values)
echo 'var [a, , b] = f()' | grasp "*"
Cannot read property 'type' of null
I have checked also flow parser. It has no problems with parsing this code. The 'ignored value' is represented by NULL in elements array:
{
"type": "ArrayPattern",
"loc": {
"source": null,
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 12
}
},
"range": [
4,
12
],
"elements": [
{
"type": "Identifier",
"loc": {
"source": null,
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
}
},
"range": [
5,
6
],
"name": "a",
"typeAnnotation": null,
"optional": false
},
null,
{
"type": "Identifier",
"loc": {
"source": null,
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 11
}
},
"range": [
10,
11
],
"name": "b",
"typeAnnotation": null,
"optional": false
}
],
"typeAnnotation": null
},
Please fix this, it fails in manu other scenarios: echo 'const [, , , fieldName] = process.argv' | grasp -s 'program' Cannot read property 'type' of null
Acorn also emits null , see example: $ echo 'const [, , , fieldName] = process.argv' | acorn { "type": "Program", "start": 0, "end": 39, "body": [ { "type": "VariableDeclaration", "start": 0, "end": 38, "declarations": [ { "type": "VariableDeclarator", "start": 6, "end": 38, "id": { "type": "ArrayPattern", "start": 6, "end": 23, "elements": [ null, null, null, { "type": "Identifier", "start": 13, "end": 22, "name": "fieldName" } ] }, "init": { "type": "MemberExpression", "start": 26, "end": 38, "object": { "type": "Identifier", "start": 26, "end": 33, "name": "process" }, "property": { "type": "Identifier", "start": 34, "end": 38, "name": "argv" }, "computed": false } } ], "kind": "const" } ], "sourceType": "script" }