-
-
Notifications
You must be signed in to change notification settings - Fork 722
feat(mangler): mangle private class members #14027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(mangler): mangle private class members #14027
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 #14027 will not alter performanceComparing Summary
Footnotes |
c25331e to
3d5b891
Compare
9d2c47e to
ed0d229
Compare
ed0d229 to
20c266b
Compare
20c266b to
5f62088
Compare
26abcd8 to
caaa44b
Compare
5f62088 to
8274783
Compare
Merge activity
|
Mangle private class members. For example, transform
```js
class C {
#foo = 0;
#bar() {}
}
```
to
```js
class C {
#e = 0;
#t() {}
}
```
.
The private members for each classes are collected from `semantic.classes()`. The renaming happens in the codegen. This way we don't need additional traverse.
caaa44b to
aac45ef
Compare
8274783 to
0fe4d95
Compare
…ate class member mangling (#14380) Add `with_private_member_mappings()` support in napi playground like PR #14027 did ## Summary Successfully added support for private member mappings in the napi playground, enabling proper mangling of private class members (e.g., `#field` → `#a`). ## Changes Made: - [x] Update `MinifierReturn` struct to include `class_private_mappings` field - [x] Update `Minifier::build()` method to capture and return `class_private_mappings` from Mangler - [x] Update `apply_minification()` to return `Option<MinifierReturn>` instead of tuple - [x] Update `codegen()` to accept `Option<MinifierReturn>` directly - [x] Refactor `collect_private_members_from_semantic` to be called inside `build_with_semantic` - [x] Fix clippy lint warning - [x] Test the changes to ensure mangling works correctly ## Technical Details: 1. Extended `MinifierReturn` to include `class_private_mappings` field 2. Updated `Minifier::build()` to capture private member mappings 3. **Refactored to return `Option<MinifierReturn>` directly** instead of destructuring into tuple 4. Updated `codegen()` to accept the entire `MinifierReturn` struct 5. **Made `collect_private_members_from_semantic` private and called it inside `build_with_semantic`** 6. Updated `build_with_semantic` to return the collected mappings 7. **Fixed clippy lint** - replaced `.map().unwrap_or()` with `.map_or()` 8. Removed unnecessary imports (`oxc_index`, `oxc_span`, `oxc_syntax`) from playground ## Testing: ✅ All existing tests pass ✅ Mangler tests pass (including `private_member_mangling`) ✅ Minifier tests pass ✅ Manual testing confirms private members are correctly mangled ✅ `just minsize` runs successfully ✅ Clippy warnings fixed The implementation now matches the pattern used in `crates/oxc/src/compiler.rs` from PR #14027. <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > Add `with_private_member_mappings()` in @oxc-project/oxc/files/napi/playground/src/lib.rs like @oxc-project/oxc/pull/14027 did </details> <!-- START COPILOT CODING AGENT TIPS --> --- 💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click [here](https://survey3.medallia.com/?EAHeSx-AP01bZqG0Ld9QLQ) to start the survey.

Mangle private class members. For example, transform
to
.
The private members for each classes are collected from
semantic.classes(). The renaming happens in the codegen. This way we don't need additional traverse.