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

prefer-default-parameters: Fix non-iterable visitorKeys #1013

Merged
merged 9 commits into from Jan 25, 2021
Merged

prefer-default-parameters: Fix non-iterable visitorKeys #1013

merged 9 commits into from Jan 25, 2021

Conversation

medusalix
Copy link
Contributor

@medusalix medusalix commented Jan 12, 2021

ESLint's visitorKeys apparently doesn't have an entry for ExperimentalRestProperty nodes, which leads to a TypeError when iterating over the keys in containsCallExpression. I couldn't find a way to trigger this behavior in a test case.

Fixes #966

@fisker
Copy link
Collaborator

fisker commented Jan 12, 2021

It's babel ast , use babel parser to test it.

@fisker
Copy link
Collaborator

fisker commented Jan 13, 2021

eslint-visitor-keys seems have ExperimentalRestProperty, https://github.com/eslint/eslint-visitor-keys/blob/2d7be11e4d13ac702c9fe3c529cadbd75b370146/lib/visitor-keys.json#L90

@fisker
Copy link
Collaborator

fisker commented Jan 13, 2021

Located problem babel-eslint use require("@babel/types").VISITOR_KEYS, and ExperimentalRestProperty was removed.

@fisker
Copy link
Collaborator

fisker commented Jan 13, 2021

Do you think we can fallback to Object.keys(node) as visitorKeys? But should exclude some keys like parent.

@fisker
Copy link
Collaborator

fisker commented Jan 13, 2021

@medusalix Can you also check this line,

const hasRest = lastProperty && lastProperty.type === 'RestElement';
should have the same problem.

Base automatically changed from master to main January 23, 2021 11:04
@medusalix
Copy link
Contributor Author

eslint-visitor-keys seems have ExperimentalRestProperty, eslint/eslint-visitor-keys@2d7be11/lib/visitor-keys.json#L90

@fisker That's great. I've added getKeys from eslint-visitor-keys as a fallback instead of returning true by default.

@fisker
Copy link
Collaborator

fisker commented Jan 24, 2021

I changed to use eslintVisitorKeys.KEYS, getKeys will return some objects not a Node, if we use it, we'll need check node.type to make sure it's a ESTree node.

But with eslintVisitorKeys.KEYS, I think ExperimentalRestProperty is the only thing we got from there, maybe we can just hard code visitorKeys for ExperimentalRestProperty?

@medusalix
Copy link
Contributor Author

But with eslintVisitorKeys.KEYS, I think ExperimentalRestProperty is the only thing we got from there, maybe we can just hard code visitorKeys for ExperimentalRestProperty?

There are unfortunately more cases that have to be considered: ChainExpression, ExperimentalSpreadProperty and ImportExpression are also not included in ESLint's visitor keys.
I've added tests for ChainExpression and ImportExpression. The ExperimentalSpreadProperty was apparently already changed to SpreadElement.

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

Successfully merging this pull request may close these issues.

TypeError: source.visitorKeys[node.type] is not iterable
3 participants