-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
fix: Reset child scopes when scope.crawl()
#17170
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
Conversation
liuxingbaoyu
commented
Mar 9, 2025
Q | A |
---|---|
Fixed Issues? | Fixes #3733 |
Patch: Bug Fix? | √ |
Major: Breaking Change? | |
Minor: New Feature? | |
Tests Added + Pass? | √ |
Documentation PR Link | |
Any Dependency Changes? | |
License | MIT |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/58834 |
scope.uids = Object.create(null); | ||
scope.data = Object.create(null); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper seems to be a genuine scope method, I think it could be public as well since the scope.data
is user defined: They might want to override the resetScope
method to do custom data cleanup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer not to expose it to users, since we've reduced public methods as much as possible in Babel 8, and they couldn't be overridden before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rethought it, it seems we shouldn't reset data
.
The current behavior is not very good either, currently only one scope's .data
is reset when calling crawl()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently only one scope's .data is reset when calling crawl().
Yes, it is the status quo and we probably don't want to break it in a patch release. We can't predict whether the data should be adapted to any AST changes: For example, if scope.data.depth
is the depth of current scope, then resetting it outside a crawl()
call is definitively breaking. While if scope.data.interestedReferencesCount
is the number of references to user-defined special identifiers, then it should be reset.