E533 [7.x backport] fix: Rename switch discriminant references when body creates shadowing variable by magic-akari · Pull Request #17737 · babel/babel · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@magic-akari
Copy link
Contributor
@magic-akari magic-akari commented Jan 27, 2026
Q                       A
Fixed Issues? Fixes #17684
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Backport of #17685

Copilot AI review requested due to automatic review settings January 27, 2026 17:27
@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories 7.x: backport labels Jan 27, 2026
@babel-bot
Copy link
Collaborator
babel-bot commented Jan 27, 2026

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

Copy link
Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR is a backport to the 7.x branch that fixes issue #17684, where switch statement discriminants were not properly renamed when the switch body introduced a shadowing variable during block scoping transformation. The fix ensures that identifiers in switch discriminants are correctly renamed when they reference variables that are shadowed within the switch statement's cases.

Changes:

  • Added logic in the renamer to requeue switch discriminants for renaming when shadowing occurs
  • Added comprehensive test coverage with 5 test cases covering different discriminant expressions (simple identifiers, member expressions, binary expressions, call expressions)

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 20 comments.

Show a summary per file
File Description
packages/babel-traverse/src/scope/lib/renamer.ts Adds logic to requeue switch statement discriminants when a shadowing variable is introduced in the switch body, mirroring the existing pattern for method computed keys and decorators
packages/babel-plugin-transform-block-scoping/test/fixtures/regression/issue-17684/input.js Input test file with 5 test cases covering various switch discriminant patterns with shadowing variables
packages/babel-plugin-transform-block-scoping/test/fixtures/regression/issue-17684/output.js Expected output showing correctly renamed discriminant references
packages/babel-plugin-transform-block-scoping/test/fixtures/regression/issue-17684/options.json Test configuration specifying the transform-block-scoping plugin
packages/babel-plugin-transform-block-scoping/test/fixtures/exec/switch-shadowing.js Executable test file verifying runtime behavior with expect assertions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pkg-pr-new
Copy link
pkg-pr-new bot commented Jan 27, 2026

Open in StackBlitz

commit: 26e1cba

@nicolo-ribaudo nicolo-ribaudo merged commit 229eb45 into babel:7.x Jan 28, 2026
65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.x: backport 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.

4 participants

0