Files
oxc-guard 0389c4010e release(crates): oxc v0.146.0 (#25912)
### 🚀 Features

- 83cb516 minifier: Improve negation of expressions in boolean context (#25755) (Armano)

### 🐛 Bug Fixes

- 134fb22 isolated-declarations: Preserve unresolved parameter types (#25909) (Dunqing)
- 526c2b3 codegen: Remove deprecated test APIs (#25889) (camc314)
- 344a9b2 codegen: Align enum template sourcemaps (#25872) (camc314)

### ⚡ Performance

- 5ef0c93 minifier: Unwrap all unary exprs without creating dummy expressions (#25891) (Armano)
- 8783524 packages/codegen: Remove loop from `growMappingBuffer` (#25886) (overlookmotel)
- b6b14c0 packages/codegen: Remove redundant branch (#25885) (overlookmotel)
- be6adf0 packages/sourcemap: Make `location` passed to `recordSourceMapping` always a number (#25884) (overlookmotel)
- f720f15 packages/codegen: Take named-mapping only code off hot path in `recordSourceMapping` (#25883) (overlookmotel)
- a734af5 packages/codegen: Remove redundant setting of `last` in `printImportAttributes` and `printIf` (#25882) (overlookmotel)
- c6e44c6 packages/codegen: Combine 2 writes in `printJSXElement` (#25881) (overlookmotel)
- 8801662 packages/codegen: Remove redundant mapping from `printParams` (#25880) (overlookmotel)

### 📚 Documentation

- 5ad330e packages/codegen: Reformat comments (#25876) (overlookmotel)
2026-08-19 08:29:51 +00:00
..

Oxc Mangler

Variable name mangling for JavaScript minification.

Overview

This crate provides variable name mangling capabilities for JavaScript minification. It shortens variable names to reduce bundle size while preserving program semantics and ensuring gzip-friendly output.

Key Features

  • Intelligent mangling: Shortens variable names while avoiding conflicts
  • Scope-aware: Respects JavaScript scoping rules
  • Gzip optimization: Generates names that compress well
  • Configurable: Options to preserve specific names or patterns
  • Base54 encoding: Efficient character usage for maximum compression

Architecture

Mangling Strategy

  1. Symbol Analysis: Identify all variables and their scopes
  2. Frequency Analysis: Count usage to optimize for common variables
  3. Name Generation: Generate short names using base54 encoding
  4. Conflict Resolution: Ensure no naming conflicts across scopes
  5. Integration: Update symbol table with new names

Base54 Encoding

Uses a character set optimized for JavaScript identifiers:

  • First character: a-zA-Z_$ (54 options)
  • Subsequent characters: a-zA-Z0-9_$ (64 options)
  • Generates shortest possible names: a, b, ..., aa, ab, etc.

Gzip Optimization

The mangling algorithm considers:

  • Character frequency: Prefer characters that compress well
  • Repetition patterns: Generate names that create gzip-friendly patterns
  • Context awareness: Consider surrounding code when choosing names

Integration with Minifier

The mangler works as part of the broader minification pipeline:

  1. Parse: Build AST from source code
  2. Analyze: Perform semantic analysis
  3. Mangle: Shorten variable names
  4. Transform: Apply other minification transforms
  5. Generate: Output minified code

This approach ensures maximum size reduction while maintaining correctness.