Skip to content

fix(regenerator): only remove bindings declared by the hoisted declar… - #18486

Merged
JLHwung merged 2 commits into
babel:mainfrom
joellemd:fix-regenerator-hoist-remove-outer-binding
Nov 3, 2026
Merged

JLHwung merged 2 commits into
babel:mainfrom
joellemd:fix-regenerator-hoist-remove-outer-binding

Conversation

@joellemd

Copy link
Copy Markdown
Member

…ation

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

If a generator declares a variable with the same name as something outside it, the regenerator plugin could accidentally delete the outer variable's binding. In the issue, a generator has let s, and a top-level class s quietly loses its binding. Block-scoping then thinks nothing named s exists, so it doesn't rename a const s in a sibling method. That becomes a plain var s, and new s() in the same method throws "s is not a constructor".

The fix is that the loop in hoist.ts should hover the names declared by the current statement path.getBindingIdentifiers() instead of everything hoisted so far.

@babel-bot

babel-bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

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

@pkg-pr-new

pkg-pr-new Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

commit: ad0b813

@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Nov 2, 2026
@JLHwung
JLHwung added this pull request to the merge queue Nov 3, 2026
Merged via the queue into babel:main with commit 894b222 Nov 3, 2026
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

regenerator: lowering a generator removes an outer binding with the same name, so block-scoping skips a rename (s is not a constructor)

4 participants