Skip to content

feat(minify): support property name mangling - #10374

Merged
graphite-app[bot] merged 1 commit into
mainfrom
codex/rolldown-mangle-props
Aug 26, 2026
Merged

graphite-app[bot] merged 1 commit into
mainfrom
codex/rolldown-mangle-props

Conversation

@Dunqing

@Dunqing Dunqing commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Adds output.minify.mangleProps to Rolldown's JavaScript API, native and WASI bindings, normalized output options, and chunk minification.

Feature

  • include and exclude accept JavaScript RegExp values.
  • reserved, quoted, debug, and cache are passed to Oxc.
  • Normalized options keep each RegExp source and flags.
  • Rolldown uses Oxc to mangle properties in a single JavaScript output chunk.
  • The updated cache is returned as RolldownOutput.mangleCache.

Pass the returned cache to mangleProps.cache when minifying a later unminified version of the same source to keep property names stable.

Benchmark

I benchmarked Sveltia CMS at a27c736, a real project linked by its maintainer in a Vite issue comment. Its production IIFE output contains one JavaScript chunk, matching the current limitation of property mangling.

The benchmark used the stable releases available on 2026-08-27: Vite 8.2.2 with Rolldown explicitly pinned to 1.2.6. Both variants used the same minifier configuration; the enabled variant added only:

mangleProps: {
  include: /^_(?:i18n|type|file|thumbnailFieldNames|fileMap)$/,
  quoted: true,
}

Three fresh Node.js 24.20.0 processes each ran 10 warm-up pairs and 30 measured pairs, for 90 measured pairs on an Apple M4 Max.

Measurement Disabled Enabled Change
In-memory vite.build() median 987.01 ms 998.63 ms +11.63 ms
Raw JavaScript 2,001,264 B 2,000,778 B -486 B (-0.0243%)
gzip level 9 613,427 B 613,317 B -110 B (-0.0179%)
Brotli quality 11 491,776 B 491,791 B +15 B (+0.0031%)

The median paired timing change was +1.25%, with a bootstrap 95% confidence interval of +0.70% to +1.49% on this machine. The output-size difference was effectively neutral for this conservative five-property allowlist.

The timer covered Vite transformation, Rolldown bundling and minification, source-map generation, and in-memory output generation for the IIFE. It did not include configuration loading, disk writes, compression, packaging-only plugins, or Sveltia's second ESM output, so these numbers are not full pnpm build wall time.

The pinned source tree passed all 8,202 upstream tests. Both generated artifacts also passed the same headless-browser CMS flow with no console, page, or network errors, and an artifact diff found only the 135 expected occurrences of the five allowlisted property names.

Limitation

Property mangling currently supports only one JavaScript output chunk. Rolldown returns an error when mangleProps is used with multiple JavaScript chunks.

Property mangling recognizes property syntax and annotated key strings. It cannot find property names in arbitrary runtime strings.

Reserve names accessed indirectly, through module namespace objects, by external or host code, or by code added after minification.

Tests cover the single-chunk output, returned cache and reuse, reserved names, regular expression flags, source maps, normalized options, and the multi-chunk error.

AI assistance disclosure: OpenAI Codex and Claude were used for research, implementation, adversarial review, testing, and PR preparation. The author will review and take responsibility for the changes before marking the draft ready.

@netlify

netlify Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit 2ba4bdf
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6a8ea0a346faf70007cb43a6
😎 Deploy Preview https://deploy-preview-10374--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@Dunqing
Dunqing force-pushed the codex/rolldown-mangle-props branch from 8e17ad4 to 612ed99 Compare July 22, 2026 09:51
@socket-security

socket-security Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

No dependency changes detected. Learn more about Socket for GitHub.

👍 No dependency changes detected in pull request

@Dunqing
Dunqing force-pushed the codex/rolldown-mangle-props branch 3 times, most recently from 985f029 to b2c4b05 Compare July 28, 2026 05:47
@Dunqing
Dunqing force-pushed the codex/rolldown-mangle-props branch from b2c4b05 to 172fb3f Compare July 30, 2026 11:15
@izaakschroeder

Copy link
Copy Markdown

Appreciate this change 😄

@Dunqing
Dunqing force-pushed the codex/rolldown-mangle-props branch 10 times, most recently from 34a4957 to 5ee9c48 Compare August 11, 2026 02:43
@Dunqing
Dunqing force-pushed the codex/rolldown-mangle-props branch 3 times, most recently from 3b34548 to 398d94f Compare August 12, 2026 02:20
@Dunqing
Dunqing force-pushed the codex/rolldown-mangle-props branch 4 times, most recently from 575d006 to 47e860a Compare August 17, 2026 06:22
graphite-app Bot pushed a commit to oxc-project/oxc that referenced this pull request Aug 17, 2026
Oxc can shorten variable names and private class names, but it cannot shorten property names such as `obj._field`. This change adds optional property mangling. It replaces #23772 and gives bundlers a way to use the same property names across several files.

### Feature

- `include` selects names to mangle. `exclude` and `reserved` keep names unchanged.
- The cache can give a property a fixed output name or keep it unchanged.
- The mangler supports member access, object and class keys, destructuring, optional chains, the left side of `in`, and JSX property names.
- `mangle_quoted` also handles strings and template literals used directly as property keys. `/* @__KEY__ */` and `/* #__KEY__ */` can mark one other string or template literal as a property key.
- Short names are assigned in a stable order. More common properties get shorter names. Existing and reserved names are avoided.
- Bundlers can collect names from several programs, create one shared map, and apply it to every program.
- Numeric keys, `__proto__`, `constructor`, `prototype`, TypeScript-only keys, and private names are never changed by this pass.

### Design

Property names are part of JavaScript syntax, not local scope. For this reason, the code lives in `oxc_minifier`. It only reuses the short-name generator from `oxc_mangler`.

For one program, the order is:

```text
collect names → assign names → rewrite once → compress → mangle variables and private names
```

Property names are rewritten before compression because compression can remove information about quotes and comments.

For several programs, a bundler collects names from each program, merges the results, assigns one shared map, and rewrites each program once. Collection can run in parallel. All programs must use the same options.

The shared map keeps property names consistent inside one build. The cache has a different job: it keeps fixed names and reservations across separate minify calls.

### Example

With `include: "^_"` and `mangle_quoted: true`:

```js
obj[`_field`] = 1;
obj._field = 2;
```

becomes:

```js
obj[`e`] = 1;
obj.e = 2;
```

### Limitation

- Property mangling is unsafe when other code still uses the old property name. Public APIs and names shared with external code, host APIs, imported namespace objects, or separate builds must be excluded or reserved.
- Quote handling is per use. Without `mangle_quoted`, `obj._field` may change while `obj["_field"]` does not.
- The mangler cannot find names built at runtime or stored in arbitrary strings. Code that uses `eval`, `Function`, or `with` must reserve any affected names.
- Compression may create a matching property after this pass has finished. For example, `'f' + 'oo_'` may later become `foo_` and will not be mangled.
- TypeScript enum reverse mappings are not supported because the transform creates quoted strings.
- Multi-program support is a caller API. The caller must collect every program that shares mangled properties before assigning names.

The public `oxc-minify` API is stacked in #24741. The downstream multi-chunk integration is shown in rolldown/rolldown#10374.

Supersedes #23772.

AI assistance: OpenAI Codex and Claude were used for research, implementation, review, and testing. The contributor is responsible for reviewing and understanding the changes before submission.
@Dunqing
Dunqing force-pushed the codex/rolldown-mangle-props branch 2 times, most recently from 53b746b to 02c65b7 Compare August 18, 2026 06:12
@sapphi-red
sapphi-red requested review from sapphi-red and removed request for sapphi-red August 23, 2026 09:39
@Dunqing
Dunqing force-pushed the codex/rolldown-mangle-props branch from eacc115 to 8ce7359 Compare August 24, 2026 02:13
@sapphi-red

Copy link
Copy Markdown
Member

Property mangling currently supports only one JavaScript output chunk.

(just in case) If this is expected to take time, it would be nice to have an issue so that users can track the feature.

@Dunqing

Dunqing commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Property mangling currently supports only one JavaScript output chunk.

(just in case) If this is expected to take time, it would be nice to have an issue so that users can track the feature.

I will do it soon

@Dunqing

Dunqing commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Property mangling currently supports only one JavaScript output chunk.

(just in case) If this is expected to take time, it would be nice to have an issue so that users can track the feature.

I will do it soon

created #10771

@Dunqing
Dunqing force-pushed the codex/rolldown-mangle-props branch from 41891ee to 71669ff Compare August 26, 2026 07:08

hyfdev commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Merge activity

  • Aug 26, 8:14 AM UTC: The merge label 'graphite: merge-when-ready' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Aug 26, 8:15 AM UTC: hyfdev added this pull request to the Graphite merge queue.
  • Aug 26, 8:22 AM UTC: Merged by the Graphite merge queue.

Adds `output.minify.mangleProps` to Rolldown's JavaScript API, native and WASI bindings, normalized output options, and chunk minification.

### Feature

- `include` and `exclude` accept JavaScript `RegExp` values.
- `reserved`, `quoted`, `debug`, and `cache` are passed to Oxc.
- Normalized options keep each `RegExp` source and flags.
- Rolldown uses Oxc to mangle properties in a single JavaScript output chunk.
- The updated cache is returned as `RolldownOutput.mangleCache`.

Pass the returned cache to `mangleProps.cache` when minifying a later unminified version of the same source to keep property names stable.

### Limitation

Property mangling currently supports only one JavaScript output chunk. Rolldown returns an error when `mangleProps` is used with multiple JavaScript chunks.

Property mangling recognizes property syntax and annotated key strings. It cannot find property names in arbitrary runtime strings.

Reserve names accessed indirectly, through module namespace objects, by external or host code, or by code added after minification.

Tests cover the single-chunk output, returned cache and reuse, reserved names, regular expression flags, source maps, normalized options, and the multi-chunk error.

AI assistance disclosure: OpenAI Codex and Claude were used for research, implementation, adversarial review, testing, and PR preparation. The author will review and take responsibility for the changes before marking the draft ready.
@graphite-app
graphite-app Bot force-pushed the codex/rolldown-mangle-props branch from 71669ff to 2ba4bdf Compare August 26, 2026 08:15
@graphite-app
graphite-app Bot merged commit 2ba4bdf into main Aug 26, 2026
36 checks passed
@graphite-app
graphite-app Bot deleted the codex/rolldown-mangle-props branch August 26, 2026 08:22
@rolldown-guard rolldown-guard Bot mentioned this pull request Aug 26, 2026
shulaoda added a commit that referenced this pull request Aug 26, 2026
## [1.2.6] - 2026-08-26

### 🚀 Features

- minify: support property name mangling (#10374) by @Dunqing
- add `tsconfig: string` option to `transform` (#10727) by @sapphi-red
- rolldown_plugin_vite_transform: add `tsconfig` option (#10725) by @sapphi-red
- rolldown_plugin_vite_resolve: add top-level `tsconfig` option (#10724) by @sapphi-red
- dev: expose module graph queries on the dev engine handle (#10716) by @h-a-n-a

### 🐛 Bug Fixes

- dev: assign import bindings before initializing dependencies (#10783) by @h-a-n-a
- dev: copy star re-exports before initializing dependencies (#10761) by @h-a-n-a
- dev: register an empty exports object for a module without exports (#10772) by @h-a-n-a
- name the module when a `codeSplitting` group callback returns a wrong type (#10753) by @IWANABETHATGUY
- dev: map dev rename events like build watch (#10758) by @shulaoda
- clear resolution cache when `TsconfigCache::clear` is called (#10726) by @sapphi-red
- dev: resolve in-flight `ensureLatestBuildOutput` when the engine closes (#10730) by @h-a-n-a
- binding: replace undeclared BindingErrorsOr with BindingResult in hook types (#10717) by @h-a-n-a

### 🚜 Refactor

- rolldown_fs_watcher: collapse fs-watcher backends behind a single FsWatcher (#10735) by @shulaoda
- hoist invariants out of the `codeSplitting` group loop (#10744) by @IWANABETHATGUY

### 📚 Documentation

- document shared notify rename mapping (#10759) by @shulaoda
- update watch-mode internals for unified FsWatcher (#10736) by @shulaoda

### ⚡ Performance

- batch `codeSplitting` group `test` / `name` calls (#10745) by @IWANABETHATGUY
- deduplicate used symbol ref readers (#10742) by @Boshen
- reduce release debug formatting (#10728) by @Boshen
- enable compiler cache via `module.enableCompileCache()` (#10678) by @btea
- deduplicate regress codegen (#10732) by @Boshen

### 🧪 Testing

- define: add expected failure for default parameter scope (#10780) by @hyfdev
- use an absolute filename for transform tsconfig path (#10782) by @shulaoda

### ⚙️ Miscellaneous Tasks

- deps: upgrade oxc to 0.147.0 (#10767) by @camc314
- deps: update resolver dependencies (#10766) by @Boshen
- deps: update rollup submodule for tests to v4.62.5 (#10770) by @rolldown-guard[bot]
- deps: update dependency vite-plus to ^0.3.0 (#10757) by @renovate[bot]
- deps: update npm packages (#10750) by @renovate[bot]
- deps: update rust crates (#10748) by @renovate[bot]
- deps: update rust crate napi to v3.12.2 (#10738) by @renovate[bot]
- deps: update dependency rust to v1.98.0 (#10733) by @renovate[bot]
- wasi: cap each Node Test attempt with timeout to survive hangs (#10709) by @hyfdev

Co-authored-by: shulaoda <[email protected]>
logaretm added a commit to getsentry/sentry-javascript that referenced this pull request Aug 26, 2026
rolldown 1.2.6 ships oxc's property mangler (rolldown/rolldown#10374), so the terser
config the rollup build used can be ported back: `mangle.reserved` and the
`/^_[^_]/` property regex with its reserved list.

The option is `minify.mangleProps`, not `minify.mangle.properties` - the latter is the
oxc-level interface the reference docs describe and rolldown ignores it silently.
logaretm added a commit to getsentry/sentry-javascript that referenced this pull request Aug 26, 2026
rolldown 1.2.6 ships oxc's property mangler (rolldown/rolldown#10374), so the terser
config the rollup build used can be ported back: `mangle.reserved` and the
`/^_[^_]/` property regex with its reserved list.

The option is `minify.mangleProps`, not `minify.mangle.properties` - the latter is the
oxc-level interface the reference docs describe and rolldown ignores it silently.
logaretm added a commit to getsentry/sentry-javascript that referenced this pull request Aug 27, 2026
rolldown 1.2.6 ships oxc's property mangler (rolldown/rolldown#10374), so the terser
config the rollup build used can be ported back: `mangle.reserved` and the
`/^_[^_]/` property regex with its reserved list.

The option is `minify.mangleProps`, not `minify.mangle.properties` - the latter is the
oxc-level interface the reference docs describe and rolldown ignores it silently.
logaretm added a commit to getsentry/sentry-javascript that referenced this pull request Aug 27, 2026
rolldown 1.2.6 ships oxc's property mangler (rolldown/rolldown#10374), so the terser
config the rollup build used can be ported back: `mangle.reserved` and the
`/^_[^_]/` property regex with its reserved list.

The option is `minify.mangleProps`, not `minify.mangle.properties` - the latter is the
oxc-level interface the reference docs describe and rolldown ignores it silently.
Brooooooklyn added a commit that referenced this pull request Aug 28, 2026
Brings oxc 0.147.0, v1.2.6, and minify property name mangling (#10374).
Conflict notes:
- binding_normalized_options.rs: main's new MinifyOptions::Enabled struct
  arm (mangle_props) placed inside our try_get_inner Option-take wrapper.
- binding_dev_engine.rs: main's BindingOutputs::from(BundleOutput) change
  applied inside our async-callback closures, so the dev engine forwards
  the mangle cache too.
- transform-to-rollup-output.ts: main's mangleCache attach kept; our
  eager-free loop stays the last block before return.
- binding_magic_string.rs: JsRegExp import moved to oxc_napi; our
  drop_inner machinery untouched.
- packages/browser keeps private: true on top of main's 1.2.6.
All three declaration flavors regenerated; the threadless memory pin
holds (1027 pages >= new 1025-page minimum).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
logaretm added a commit to getsentry/sentry-javascript that referenced this pull request Sep 23, 2026
rolldown 1.2.6 ships oxc's property mangler (rolldown/rolldown#10374), so the terser
config the rollup build used can be ported back: `mangle.reserved` and the
`/^_[^_]/` property regex with its reserved list.

The option is `minify.mangleProps`, not `minify.mangle.properties` - the latter is the
oxc-level interface the reference docs describe and rolldown ignores it silently.
logaretm added a commit to getsentry/sentry-javascript that referenced this pull request Oct 14, 2026
rolldown 1.2.6 ships oxc's property mangler (rolldown/rolldown#10374), so the terser
config the rollup build used can be ported back: `mangle.reserved` and the
`/^_[^_]/` property regex with its reserved list.

The option is `minify.mangleProps`, not `minify.mangle.properties` - the latter is the
oxc-level interface the reference docs describe and rolldown ignores it silently.

This branch was previously deployed

1 inactive deployment
void — 2ba4bdfc Deployed Aug 26, 2026 by graphite-app[bot] via Deploy to Void #4150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants