Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Improve getBindingIdentifiers#16544

Merged
JLHwung merged 6 commits into
babel:mainfrom
JLHwung:improve-get-binding-identifiers
Jun 4, 2024
Merged

Improve getBindingIdentifiers#16544
JLHwung merged 6 commits into
babel:mainfrom
JLHwung:improve-get-binding-identifiers

Conversation

@JLHwung
Copy link
Copy Markdown
Contributor

@JLHwung JLHwung commented Jun 3, 2024

Q                       A
Fixed Issues? getOuterBindingIdentifiers should not return the class id for class expressions
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

When newBindingOnly is true, getBindingIdentifiers will not consider an UpdateExpression as a binding path.

More tests are also provided.

@JLHwung JLHwung added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Jun 3, 2024
@JLHwung JLHwung force-pushed the improve-get-binding-identifiers branch from 395f202 to b19e582 Compare June 3, 2024 04:54
@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Jun 3, 2024

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

@JLHwung JLHwung marked this pull request as draft June 3, 2024 06:08
!path.get("id").node[NOT_LOCAL_BINDING]
) {
path.scope.registerBinding("local", path);
path.scope.registerBinding("local", path.get("id"), path);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since the changes in @babel/types will break old versions of @babel/traverse, here we defer the ClassExpression change to Babel 8. On the other hand, the UpdateExpression change does not break other packages, so we could ship it in Babel 7.

@JLHwung JLHwung force-pushed the improve-get-binding-identifiers branch from 7fbab12 to 6852dc3 Compare June 3, 2024 06:32
@JLHwung JLHwung added PR: Bug Fix (next major) 🐛 A type of pull request used for our changelog categories for next major release and removed PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Jun 3, 2024
@JLHwung JLHwung marked this pull request as ready for review June 3, 2024 06:45
Comment on lines 58 to 60
// TODO(@nicolo-ribaudo): Check if we can remove them from .keys in a
// backward-compatible way, and if not what we need to do to remove them
// in Babel 8.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Even if you are not me, would you like to do this? :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Our scope tracker would register constant violations based on the information here. I think we need a utility such as getAssignmentIdentifiers for the assignment pattern as getBindingIdentifiers for the binding pattern, which we already have. They will definitely share the destructuring AST access but getAssignmentIdentifiers will also handle assignments, update and delete expressions as well.

Because it will be a small feature either for @babel/types or for @babel/traverse, I suggest we open a separate PR for that.

@JLHwung JLHwung merged commit 07bd000 into babel:main Jun 4, 2024
@JLHwung JLHwung deleted the improve-get-binding-identifiers branch June 4, 2024 09:06
@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 Sep 4, 2024
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 4, 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 (scope) PR: Bug Fix (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.

4 participants