Skip to content

feat(minifier): remove unused variable declarations in dead code#13754

Merged
graphite-app[bot] merged 1 commit intomainfrom
09-14-feat_minifier_remove_unused_variable_declarations_in_dead_code
Sep 14, 2025
Merged

feat(minifier): remove unused variable declarations in dead code#13754
graphite-app[bot] merged 1 commit intomainfrom
09-14-feat_minifier_remove_unused_variable_declarations_in_dead_code

Conversation

@sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Sep 14, 2025

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

if (false) { var a; console.log(a) }
(function () { return; var a })()

@github-actions github-actions bot added A-minifier Area - Minifier C-enhancement Category - New feature or request labels Sep 14, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@sapphi-red sapphi-red requested a review from Boshen September 14, 2025 10:17
@sapphi-red sapphi-red marked this pull request as ready for review September 14, 2025 10:17
Copilot AI review requested due to automatic review settings September 14, 2025 10:17
Copy link
Contributor

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 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_declaration function 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-hq
Copy link

codspeed-hq bot commented Sep 14, 2025

CodSpeed Instrumentation Performance Report

Merging #13754 will not alter performance

Comparing 09-14-feat_minifier_remove_unused_variable_declarations_in_dead_code (c868796) with main (db33196)1

Summary

✅ 37 untouched

Footnotes

  1. No successful run was found on main (c868796) during the generation of this report, so db33196 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Sep 14, 2025
Copy link
Member

Boshen commented Sep 14, 2025

Merge activity

)

Unused variable declarations in dead code was not removed. For example, the following cases was not removed:
```js
if (false) { var a; console.log(a) }
```
```js
(function () { return; var a })()
```
@graphite-app graphite-app bot force-pushed the 09-14-feat_minifier_remove_unused_variable_declarations_in_dead_code branch from d746da8 to c868796 Compare September 14, 2025 12:50
@graphite-app graphite-app bot merged commit c868796 into main Sep 14, 2025
25 checks passed
@graphite-app graphite-app bot deleted the 09-14-feat_minifier_remove_unused_variable_declarations_in_dead_code branch September 14, 2025 12:55
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Sep 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants