Repository navigation
feat(minify): support property name mangling - #10374
Conversation
✅ Deploy Preview for rolldown-rs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
8e17ad4 to
612ed99
Compare
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
985f029 to
b2c4b05
Compare
b2c4b05 to
172fb3f
Compare
|
Appreciate this change 😄 |
34a4957 to
5ee9c48
Compare
3b34548 to
398d94f
Compare
575d006 to
47e860a
Compare
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.
53b746b to
02c65b7
Compare
eacc115 to
8ce7359
Compare
(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 |
41891ee to
71669ff
Compare
Merge activity
|
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.
71669ff to
2ba4bdf
Compare
## [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]>
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.
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.
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.
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.
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
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.
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.
Adds
output.minify.manglePropsto Rolldown's JavaScript API, native and WASI bindings, normalized output options, and chunk minification.Feature
includeandexcludeaccept JavaScriptRegExpvalues.reserved,quoted,debug, andcacheare passed to Oxc.RegExpsource and flags.RolldownOutput.mangleCache.Pass the returned cache to
mangleProps.cachewhen 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:
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.
vite.build()medianThe 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 buildwall 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
manglePropsis 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.