Repository navigation
fix(class-static-block): skip class body path with stale ancestry - #18563
Merged
JLHwung merged 1 commit intoNov 11, 2026
Merged
Conversation
When static blocks are run through `_staticBlock()` after a class expression, the ClassBody visitor wraps the class in a sequence expression. `replaceWith` re-points the class path to the sequence, so other plugins visiting the class members in the same traversal saw no class above the constructor: the arrow functions lowering (used by async-to-generator) then treated a derived constructor as a base one and read `this` before `super()`. Skip the class body: the requeued sequence expression visits it again with the right ancestry. Fixes babel#18558 Assisted-by: Claude Opus 5.5
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63106 |
|
commit: |
nicolo-ribaudo
approved these changes
Nov 10, 2026
Collaborator
|
Backported to 7.x in #18579. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This bug is very interesting. What's happening here is that when static blocks are run through
_staticBlock()after a class expression, theClassBodyvisitor wraps the class in a sequence expression. Then thereplaceWithre-points the class path to the wrapped sequence expression, so other plugins visiting the class members in the same traversal saw no class above the constructor: the arrow functions lowering (used byasync-to-generator) then treated a derived constructor as a base one and readthisbeforesuper().So in this PR we provide a hotfix for this case: we skip the class body path with stale ancestry given that it will be revisited later in the sequence expression with correct ancestry. This bug is an example of why we should avoid replacing parent path in the visitors.
I am still exploring if we can fix this issue on the
replaceWithside: That it will check if one of the children becomes stale and it is pushed to a new location then we can automatically remove it from the current traverse queue. This approach does not require an explicitpath.skip()in such cases but do incurs ~2% performance impact. Anyway such change will be a bigger PR so I don't want to hold off the fix for a more general one.Assisted-by: Claude Opus 5.5