feat(mangler): mangle private class names
$ cat test.js
class Foo {
constructor(k) {
this.#kasd = k;
}
getK() {
return this.#kasd;
}
}
class Foo2 {
constructor(k) {
this.#kasd = k;
}
getK() {
return this.#kasd;
}
}
export { Foo, Foo2 };
$ cargo run -p oxc_minifier --example minifier -- --mangle
Compiling oxc_mangler v0.51.0 (/Users/cameron/github/Boshen/oxc/crates/oxc_mangler)
Compiling oxc_minifier v0.51.0 (/Users/cameron/github/Boshen/oxc/crates/oxc_minifier)
Finished `dev` profile [unoptimized] target(s) in 0.96s
Running `target/debug/examples/minifier --mangle`
class Foo {
constructor(e) {
this.#e = e;
}
getK() {
return this.#e;
}
}
class Foo2 {
constructor(e) {
this.#e = e;
}
getK() {
return this.#e;
}
}
export { Foo, Foo2 };
No diff on cargo misize. looks like non of the test suite has classes with private class members
- #9279
๐ (View in Graphite) - #9278

main
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.
CodSpeed Performance Report
Merging #9279 will degrade performances by 88.4%
Comparing c/02-21-feat_mangler_mangle_private_class_names (9106d71) with main (4ad328b)
Summary
โ 3 regressions
โ
30 untouched benchmarks
:warning: Please fix the performance issues or acknowledge them on CodSpeed.
Benchmarks breakdown
| Benchmark | BASE |
HEAD |
Change | |
|---|---|---|---|---|
| โ | mangler[antd.js] |
16.2 ms | 139.3 ms | -88.4% |
| โ | mangler[react.development.js] |
299.4 ยตs | 1,766.4 ยตs | -83.05% |
| โ | mangler[typescript.js] |
39.8 ms | 280.4 ms | -85.79% |
This adds an additional AST pass, but how come it's not shown on the benchmark ๐ค ?
so i implemented this inside:
https://github.com/oxc-project/oxc/blob/82c354a1c23d0581c5be94ed50317291f39102fd/crates/oxc_minifier/src/lib.rs#L48
minifier::build. but that fn doesn't run when doing the benches. we run the mangler/minifier explicitly.
i think i could either:
- move this directly into the mangler
- move this as a minifier pass probably 1 is better?
- move this directly into the mangler
Yeah this seems better. We can also add a flag (turned off by default) to enable this.