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

Move environment-visitor helper into @babel/traverse #16577

Merged
merged 3 commits into from
Jul 15, 2024

Conversation

nicolo-ribaudo
Copy link
Member

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

I'm working on removing cycles between packages caused by type-only imports. My motivation is that, even if it's a type-only import, it's an actual conceptual cycle and those packages will always be used together anyway. For example:

  • @babel/traverse depends on @babel/helper-environment-visitor
  • @babel/helper-environment-visitor does not explicitly depend @babel/traverse, but it can only be used on NodePaths so it can only be used when @babel/traverse

This has two benefits:

  • when publishing TS types we'll need to mark them as actual dependencies, and having cycles between packages causes problems
  • we reduce the number of packages

@nicolo-ribaudo nicolo-ribaudo added this to the v7.25.0 milestone Jun 19, 2024
@nicolo-ribaudo nicolo-ribaudo added the PR: New Feature 🚀 A type of pull request used for our changelog categories label Jun 19, 2024
@babel-bot
Copy link
Collaborator

babel-bot commented Jun 19, 2024

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

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.

I recall previously we imported the traverse from their peer dependent @babel/core because of compatibility issues. Specifically we want the core, even if it is an old version, to explode any AST alias so that the traverser, imported from core, will not complain about any new AST types beyond its knowledge.

Now that visitors.environmentVisitor will explode the visitors via merge from the latest traverse, maybe we have to defer this change to Babel 8?

@nicolo-ribaudo
Copy link
Member Author

@JLHwung Most of the plugins changed in this PR already import their traverse (either from @babel/core or from @babel/traverse) rather than using the one passed as a parameter to the plugin function, so they are already potentially subject to this issue.

I will revert the change for the plugins that currently use the function parameter, so that we don't risk breaking something that is currently working.

@nicolo-ribaudo
Copy link
Member Author

Actually, the only packages where we are potentially introducing the problem is @babel/plugin-bugfix-firefox-class-in-computed-class-key. The only problematic node type is StaticBlock, which is present in the environment visitor (since it is a FunctionParent) but was only introduced in Babel 7.12.0.

I'll add a little check for it.

@nicolo-ribaudo nicolo-ribaudo merged commit 25d3561 into babel:main Jul 15, 2024
51 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the remove-cycles-1 branch July 15, 2024 21:06
@nicolo-ribaudo
Copy link
Member Author

Whops, I meant to mark as ready and I merged 😅

I guess it's fine given that we are close to a release, but I'll revert if needed.

nicolo-ribaudo added a commit that referenced this pull request Jul 16, 2024
@nicolo-ribaudo nicolo-ribaudo removed the PR: New Feature 🚀 A type of pull request used for our changelog categories label Jul 16, 2024
@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 Oct 16, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 16, 2024
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants