feat(minifier): remove unused variable declarations in dead code#13754
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds functionality to remove unused variable declarations in dead code by extending the existing dead code elimination to handle variable declarations that are defined but never used within unreachable code blocks.
- Extracts common logic for checking if unused declarators can be removed into a reusable helper method
- Adds a new
remove_unused_variable_declarationfunction to filter out unused variable declarations - Integrates unused variable removal into dead code elimination for if statements and unreachable code blocks
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/oxc_minifier/src/peephole/remove_unused_declaration.rs | Refactors existing logic into helper methods and adds new function to remove unused variable declarations |
| crates/oxc_minifier/src/peephole/remove_dead_code.rs | Integrates unused variable removal into dead code elimination and adds test cases |
| crates/oxc_minifier/src/peephole/minimize_statements.rs | Applies unused variable removal when processing kept variables from dead code |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
CodSpeed Instrumentation Performance ReportMerging #13754 will not alter performanceComparing Summary
Footnotes |
Merge activity
|
d746da8 to
c868796
Compare

Unused variable declarations in dead code was not removed. For example, the following cases was not removed: