Skip to content

Conversation

@sapphi-red
Copy link
Member

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

Mangle private class members. For example, transform

class C {
  #foo = 0;
  #bar() {}
}

to

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.

Copy link
Member Author

sapphi-red commented Sep 23, 2025


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.

@github-actions github-actions bot added A-minifier Area - Minifier A-codegen Area - Code Generation labels Sep 23, 2025
@github-actions github-actions bot added the C-enhancement Category - New feature or request label Sep 23, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Sep 23, 2025

CodSpeed Instrumentation Performance Report

Merging #14027 will not alter performance

Comparing 09-22-feat_mangler_mangle_private_class_members (0fe4d95) with main (a05cb23)1

Summary

✅ 37 untouched

Footnotes

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

@sapphi-red sapphi-red force-pushed the 09-22-feat_minifier_remove_unused_private_class_members branch from c25331e to 3d5b891 Compare September 23, 2025 05:27
@sapphi-red sapphi-red force-pushed the 09-22-feat_mangler_mangle_private_class_members branch from 9d2c47e to ed0d229 Compare September 23, 2025 05:27
@sapphi-red sapphi-red force-pushed the 09-22-feat_mangler_mangle_private_class_members branch from ed0d229 to 20c266b Compare September 23, 2025 05:50
@sapphi-red sapphi-red marked this pull request as ready for review September 23, 2025 06:37
@sapphi-red sapphi-red requested a review from Boshen September 23, 2025 06:38
@sapphi-red sapphi-red force-pushed the 09-22-feat_mangler_mangle_private_class_members branch from 20c266b to 5f62088 Compare September 23, 2025 13:20
@sapphi-red sapphi-red force-pushed the 09-22-feat_minifier_remove_unused_private_class_members branch 2 times, most recently from 26abcd8 to caaa44b Compare September 23, 2025 13:26
@sapphi-red sapphi-red force-pushed the 09-22-feat_mangler_mangle_private_class_members branch from 5f62088 to 8274783 Compare September 23, 2025 13:26
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Sep 24, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Sep 24, 2025

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.
@graphite-app graphite-app bot force-pushed the 09-22-feat_minifier_remove_unused_private_class_members branch from caaa44b to aac45ef Compare September 24, 2025 03:34
@graphite-app graphite-app bot force-pushed the 09-22-feat_mangler_mangle_private_class_members branch from 8274783 to 0fe4d95 Compare September 24, 2025 03:35
Base automatically changed from 09-22-feat_minifier_remove_unused_private_class_members to main September 24, 2025 03:40
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Sep 24, 2025
@graphite-app graphite-app bot merged commit 0fe4d95 into main Sep 24, 2025
27 checks passed
@graphite-app graphite-app bot deleted the 09-22-feat_mangler_mangle_private_class_members branch September 24, 2025 03:41
graphite-app bot pushed a commit that referenced this pull request Oct 1, 2025
graphite-app bot pushed a commit that referenced this pull request Oct 7, 2025
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-codegen Area - Code Generation 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