feat(minifier): remove unused private class members#14026
feat(minifier): remove unused private class members#14026graphite-app[bot] merged 1 commit intomainfrom
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. |
CodSpeed Instrumentation Performance ReportMerging #14026 will not alter performanceComparing Summary
Footnotes |
c25331e to
3d5b891
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds optimization to remove unused private class members (fields, methods, and accessors) from JavaScript classes during minification. The implementation tracks private member usage during AST traversal and removes unused members during class body processing.
- Adds tracking mechanism for private member usage across nested class scopes
- Implements removal logic for unused private fields, methods, and accessor properties
- Preserves members with side effects in their initializers
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/oxc_minifier/src/state.rs | Adds ClassSymbolsStack to track private member usage across class scopes |
| crates/oxc_minifier/src/peephole/remove_unused_private_members.rs | Implements the core logic for removing unused private members with comprehensive tests |
| crates/oxc_minifier/src/peephole/mod.rs | Integrates the optimization into the traversal pipeline |
| tasks/track_memory_allocations/allocs_minifier.snap | Updates memory allocation snapshots |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
26abcd8 to
caaa44b
Compare
Merge activity
|
Compress
```js
class C {
#unused = 1;
#used = 2;
method() { return this.#used; }
}
```
to
```js
class C {
#used = 2;
method() { return this.#used; }
}
```
.
The symbol usage is collected in the main traverse. The removal happens in `exit_class_body`. This way we don't need additional traverse.
caaa44b to
aac45ef
Compare

Compress
to
.
The symbol usage is collected in the main traverse. The removal happens in
exit_class_body. This way we don't need additional traverse.