oxc/crates/oxc_minifier
sapphi-red e0117db531
feat(minifier): replace const with let for non-exported read-only variables (#8733)
Replace `const` with `let` when that value does not have any assignments and not exposed.
2025-01-26 12:44:01 +00:00
..
examples refactor(minifier): side effect detection needs symbols resolution (#8715) 2025-01-25 15:01:00 +00:00
src feat(minifier): replace const with let for non-exported read-only variables (#8733) 2025-01-26 12:44:01 +00:00
tests feat(minifier): replace const with let for non-exported read-only variables (#8733) 2025-01-26 12:44:01 +00:00
Cargo.toml release(crates): v0.48.0 (#8686) 2025-01-24 12:09:37 +08:00
CHANGELOG.md release(crates): v0.48.0 (#8686) 2025-01-24 12:09:37 +08:00
README.md feat(minifier): fold array concat chaining (#8440) 2025-01-17 05:53:54 +00:00

Minifier

A JavaScript minifier has three components:

  1. printer
  2. mangler
  3. compressor

Mangler

The mangler implementation is part of the SymbolTable residing in oxc_semantic. It is responsible for shortening variables. Its algorithm should be gzip friendly.

The printer is also responsible for printing out the shortened variable names.

Compressor

The compressor is responsible for rewriting statements and expressions for minimal text output. Terser is a good place to start for learning the fundamentals.

Assumptions

  • Properties of the global object defined in the ECMAScript spec behaves the same as in the spec
    • Examples of properties: Infinity, parseInt, Object, Promise.resolve
    • Examples that breaks this assumption: globalThis.Object = class MyObject {}
  • document.all is not used or behaves as a normal object
    • Examples that breaks this assumption: console.log(typeof document.all === 'undefined')
  • TDZ violation does not happen
    • Examples that breaks this assumption: (() => { console.log(v); let v; })()
  • with statement is not used
    • Examples that breaks this assumption: with (Math) { console.log(PI); }
  • Errors thrown when creating a String or an Array that exceeds the maximum length can disappear or moved
    • Examples that breaks this assumption: try { new Array(Number(2n**53n)) } catch { console.log('log') }

Terser Tests

The fixtures are copied from https://github.com/terser/terser/tree/v5.9.0/test/compress