Skip to content

Conversation

liuxingbaoyu
Copy link
Member

@liuxingbaoyu liuxingbaoyu commented Jul 9, 2024

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

In addition to changing scope.{references,uids} to Set, we also only create them at the top-level program scope, since we never use them in child scopes.
I'm not sure if these two properties are public, but it would be good to mention it in the migration guide.

@babel-bot
Copy link
Collaborator

babel-bot commented Jul 9, 2024

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

@liuxingbaoyu
Copy link
Member Author

In fact, there are some potential problems with the current behavior. For example, when calling childPath.scope.crawl(), invalid items in references will not be removed.

Comment on lines 395 to 402
references?: Set<string>;
globals: { [name: string]: t.Identifier | t.JSXIdentifier };
uids: { [name: string]: boolean };
uids?: Set<string>;
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment saying that they are only defined in the program scope? Or maybe, we can simplify some methods by defining them in all scopes but using the same shared set.

@nicolo-ribaudo nicolo-ribaudo added the PR: Internal (next major) 🏠 A type of pull request used for our changelog categories for next major release label Mar 21, 2025
@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Mar 26, 2025

@liuxingbaoyu Do you still want to do this? (I think we should)

@liuxingbaoyu
Copy link
Member Author

Yes I will continue it!

@JLHwung
Copy link
Contributor

JLHwung commented Mar 27, 2025

If people miss the changelog from Babel 7 to Babel 8, they would have a confusing debug experience because from their point of view, scope.references[id.name] will be mostly nullish in Babel 8, and such usage does not throw any error: People may spend quite some time before they figure out what is going wrong in their plugin.

I suggest we introduce uidSet and referenceSet for the set storage and add a deprecation getter/setter for uids and references. The getter/setter will work in Babel 8 with a deprecation message, hopefully we can remove them in Babel 9.

@nicolo-ribaudo
Copy link
Member

Maybe could that getter also return a proxy that makes it work with the underlying set?

@liuxingbaoyu
Copy link
Member Author

Perhaps we could just rename uid to uidSet so the exception is thrown explicitly.

@nicolo-ribaudo nicolo-ribaudo merged commit 05f28c8 into babel:main May 30, 2025
61 checks passed
noelportillo

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Internal (next major) 🏠 A type of pull request used for our changelog categories for next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants