Skip to content
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

Array destructuring - Ignoring some returned values - Error #127

Open
adros opened this issue Jul 25, 2018 · 3 comments
Open

Array destructuring - Ignoring some returned values - Error #127

adros opened this issue Jul 25, 2018 · 3 comments

Comments

@adros
Copy link
Contributor

adros commented Jul 25, 2018

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
},
@ainthek
Copy link

ainthek commented Aug 21, 2019

Please fix this, it fails in manu other scenarios:
echo 'const [, , , fieldName] = process.argv' | grasp -s 'program'
Cannot read property 'type' of null

@ainthek
Copy link

ainthek commented Aug 21, 2019

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"
}

adros added a commit to gratex/grasp-squery that referenced this issue Sep 2, 2019
adros added a commit to gratex/grasp-squery that referenced this issue Sep 2, 2019
adros added a commit to gratex/grasp-squery that referenced this issue Sep 2, 2019
adros added a commit to gratex/grasp that referenced this issue Sep 2, 2019
@adros
Copy link
Contributor Author

adros commented Apr 3, 2024

Works here: gratex@babd2bd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants