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

fix: forward stop signal to parent path #14105

Merged
merged 5 commits into from Jan 6, 2022
Merged

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Jan 5, 2022

Q                       A
Fixed Issues? Fixes #14099
Patch: Bug Fix? Y
Tests Added + Pass? Yes
License MIT

In this PR we extract traverse.node into a new routine traverseNode that returns whether the traversal stops early. Because traverse.node is an API, traverse.node now calls traverseNode but returns undefined conditionally. path.visit() now calls traverseNode and set .shouldStop accordingly when the traversal is requested to stop.

For example,

f;g;

has AST

Program - ExpressionStatement (f;) - Identifier (f)
        - ExpressionStatement (g;) - Identifier (g)

when an Identifier visitor requests to stop by calling path.stop(), the signal is not forwarded to ExpressionStatement[] queue visitor because we simply called traverse.node() which lost track of whether the traversal stopped gracefully, so the root traversal continues to g;.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: traverse labels Jan 5, 2022
@babel-bot
Copy link
Collaborator

babel-bot commented Jan 5, 2022

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/50512/

@JLHwung JLHwung marked this pull request as draft January 5, 2022 20:24
@JLHwung JLHwung marked this pull request as ready for review January 5, 2022 21:49
@nicolo-ribaudo nicolo-ribaudo merged commit b9ba4f9 into babel:main Jan 6, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the fix-14099 branch January 6, 2022 17:38
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Apr 8, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: traverse PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: path.stop() method not working on ReferencedIdentifier/AssignmentExpression nodes
4 participants