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

prevent infinite traversal when passed cyclic structures #107

Merged
merged 3 commits into from
Apr 15, 2020
Merged

prevent infinite traversal when passed cyclic structures #107

merged 3 commits into from
Apr 15, 2020

Conversation

uni-zheng
Copy link
Contributor

When traverse unlisted keys, estraverse will iteraction this node all properties.

I think in most cases the property parent is used to reference parent node.

So I exclude parent in iteraction.

This issue was discovered while using esquery, esquery use estraverse directly without set fallback.

@michaelficarra
Copy link
Member

What tools produce parent links like this? As far as the solution goes, I'd much prefer using a seen list to this special-casing of a property named "parent".

@uni-zheng
Copy link
Contributor Author

uni-zheng commented Apr 9, 2020

@michaelficarra I know there is known keys list to find which property to access.

But estraverse has issue to handle unknown keys.

I use ESLint with babel-eslint parser to check my code. There has a loop when query unknown key JSXOpeningElement.

WechatIMG80724

WechatIMG80725

As current method that it will map all properties on unknown key to find chilren which has type prop.

@michaelficarra
Copy link
Member

@uni-zheng I don't think you're understanding. I believe you that nodes with self-references or circular references exist. I think the best way to account for this is keeping track of nodes that have been traversed to avoid traversing them more than once.

@uni-zheng
Copy link
Contributor Author

@michaelficarra You're right. I updated codes.

estraverse.js Outdated Show resolved Hide resolved
@michaelficarra michaelficarra changed the title prevent loop when unlisted key's property has parent node reference prevent infinite traversal when passed cyclic structures Apr 15, 2020
@michaelficarra michaelficarra merged commit 91489e6 into estools:master Apr 15, 2020
@michaelficarra
Copy link
Member

@uni-zheng Thanks for the contribution!

@uni-zheng
Copy link
Contributor Author

@michaelficarra Hi, I am glad to complete this contribution.

And I checked [email protected] there still use [email protected] code in npm. Could you release a new version for esquery include this codes?

@michaelficarra
Copy link
Member

@uni-zheng Sure, can you open an issue on esquery?

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.

2 participants