Files
Dunqing b13fd48471 fix(minifier): model uninitialized module vars as undefined (#25497)
An uninitialized module-level `var` is `undefined` until it is assigned. After Rolldown removed an unreachable setter, Oxc did not keep this fact, so a dead optional call could remain in the output.

This PR records safe uninitialized module `var` bindings as known `undefined`. Existing minifier passes can then remove optional chains and simplify other reads.

The optimization is limited to module scope. It is disabled for resolved writes, redeclarations, and direct `eval`. Script globals and function-local variables are not changed.

Direct aliases keep the same known value without replacing every read with `void 0`. This avoids larger output and lets the existing alias cleanup work normally.

Generic optimizer tests now use function parameters when they need an unknown value. Focused tests cover the new behavior for uninitialized module variables.

## Example

Input:

```js
var slot

function make(value) {
  slot?.(value)
  return value
}

console.log(make(1))
```

Before:

```js
var slot;
function make(value) {
  slot?.(value);
  return value;
}
console.log(make(1));
```

After:

```js
function make(value) {
  return value;
}
console.log(make(1));
```

Verified with the full `oxc_minifier` test suite (649 passed, 34 ignored), Clippy, formatting, minsize, and allocation checks. Minsize and allocation snapshots are unchanged.

Fixes rolldown/rolldown#10659

AI-assisted by OpenAI Codex.
2026-08-17 06:24:04 +00:00
..

Oxc Minifier

Next-generation JavaScript/TypeScript minifier achieving best-in-class compression.

Inspiration

  • Closure Compiler: Advanced size optimizations
  • Terser/UglifyJS: Comprehensive battle-tested transforms
  • esbuild: Efficient algorithms and architecture
  • SWC: Modern Rust performance

Key Features

  • Maximum compression through exhaustive optimizations
  • 100% correctness with comprehensive testing
  • Fixed-point iteration for optimal size
  • Arena allocation for performance

Current Performance

See tasks/minsize for compression benchmarks.

  • Matching/beating esbuild on many libraries
  • Full test262, Babel, TypeScript conformance

Usage

use oxc_minifier::{Minifier, MinifierOptions};

let options = MinifierOptions::default();
let minifier = Minifier::new(options);
let result = minifier.minify(&mut program);

Testing Infrastructure

  • just minsize - Track compression benchmarks
  • cargo coverage - Conformance tests (test262, Babel, TypeScript)
  • tasks/e2e - Real-world E2E testing

Development

  • just test - Run all tests
  • cargo run -p oxc_minifier --example minifier - Try the minifier

Key Dependencies

Documentation