Skip to content

fix(babel-traverse): automatically provide a hub when traversing a File or Program and no parentPath is given #11350#17672

Merged
JLHwung merged 3 commits intobabel:mainfrom
simbahax:main
Jan 3, 2026
Merged

fix(babel-traverse): automatically provide a hub when traversing a File or Program and no parentPath is given #11350#17672
JLHwung merged 3 commits intobabel:mainfrom
simbahax:main

Conversation

@simbahax
Copy link
Contributor

Q                       A
Fixed Issues? Fixes #11350
Patch: Bug Fix? Yes
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link N/A
Any Dependency Changes? N/A
License MIT

This PR implements the changes proposed by @JLHwung in #11350 .
I am happy to incorporate any additional feedback :)

@babel-bot
Copy link
Collaborator

babel-bot commented Dec 17, 2025

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 17, 2025

Open in StackBlitz

commit: ebc32fe

@simbahax
Copy link
Contributor Author

Not sure why CI / Test on Node.js 24 (pull_request) is failing, this appears not to be related to this PR.

@simbahax simbahax force-pushed the main branch 2 times, most recently from 8d53d1d to 6323ed0 Compare December 23, 2025 21:12
Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

Copy link
Member

@liuxingbaoyu liuxingbaoyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
I've moved the fix to prevent an empty NodePath from appearing at the top.
And added a path.getPathLocation() test, which previously returned .program.

@liuxingbaoyu
Copy link
Member

CI is unrelated to this PR and will be fixed at #17692.

@JLHwung JLHwung merged commit 30af57a into babel:main Jan 3, 2026
54 checks passed
@nicolo-ribaudo
Copy link
Member

Does this PR need to be included in Babel 7? If so, @simbahax would you mind opening a PR cherry-picking the commit (30af57a) to the 7.x branch? Thank you!

simbahax added a commit to simbahax/babel that referenced this pull request Jan 12, 2026
… parentPath is given (babel#17672)

* fix(babel-traverse): automatically provide a hub when traversing a File or Program and no parentPath is given babel#11350

* fix(babel-traverse): test failure for getStatementParent due to 37f3536

* review

---------

Co-authored-by: Babel Bot <30521560+liuxingbaoyu@users.noreply.github.com>
nicolo-ribaudo pushed a commit that referenced this pull request Jan 28, 2026
… parentPath is given (#17708)

Backport of #17672 (30af57a)

Co-authored-by: 30521560+liuxingbaoyu@users.noreply.github.com
meta-codesync bot pushed a commit to facebook/metro that referenced this pull request Feb 14, 2026
Summary:
Since D92850410 we're guaranteed to be using `babel/traverse` >= 7.29, where the old bug babel/babel#6437 is fixed by babel/babel#17672

We can remove our workaround, which included an awkward second copy of `babel/traverse`. We'll just keep a regression test around in case the upstream fix is reverted.

Reviewed By: vzaidman

Differential Revision: D92852669

fbshipit-source-id: fa25dc35d529024c783bc4dc2189aa88cf6031cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

this.hub is undefined in Babel traverse

6 participants