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

fix: fix declarator removal only deletes one binding #16584

Conversation

nerodesu017
Copy link

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

As specified above, this PR fixes a problem where removing the only VariableDeclarator of a VariableDeclaration node leads to removal (or at least attempt) of 2 Bindings with the same name from different scopes (the removal of the declarator removes the correct binding, but the removal of the declaration attempts to remove it again, and if it finds it in a parent scope, it deletes it from there too)

{
  let a = 1; // removing the VariableDeclarator removes the binding of `a` from this scope
}
let a = 2; // when the first removal hook gets called, the binding of `a` from this scope gets removed
             // this is because the `getBindingIdentifiers` function was giving the same bindings even
             // after having them removed

The current solution is a HOTFIX and documented as such in the comments of the typescript code. I am open to suggestions for making it better.

@babel-bot
Copy link
Collaborator

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

@nerodesu017 nerodesu017 deleted the fix-removal-of-declarator-removing-multiple-bindings branch June 24, 2024 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: variable declarator remove bug
2 participants