oxc/crates/oxc_minifier
2025-01-18 03:51:40 +00:00
..
examples feat(napi/minify): implement napi (#8478) 2025-01-14 08:55:55 +00:00
src feat(minifier): collapse if stmt with empty consequent (#8577) 2025-01-18 03:51:40 +00:00
tests feat(minifier): collapse if stmt with empty consequent (#8577) 2025-01-18 03:51:40 +00:00
Cargo.toml release(crates): v0.46.0 (#8487) 2025-01-14 19:40:44 +08:00
CHANGELOG.md release(crates): v0.46.0 (#8487) 2025-01-14 19:40:44 +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