oxc/crates/oxc_minifier
翠 / green aaa009dd4d
docs(minifier): clarify assumptions for compressor (#8404)
Listed the assumptions that the compressor probably makes.
2025-01-10 11:37:41 +08:00
..
examples feat(mangler): mangle top level variables (#7907) 2024-12-15 21:31:41 +08:00
src chore(deps): update dependency rust to v1.84.0 (#8391) 2025-01-09 18:11:17 +00:00
tests refactor(minifier): remove the buggy minimize_exit_points implementation (#8349) 2025-01-09 02:49:32 +00:00
Cargo.toml feat(minifier): add RemoveUnusedCode (#8210) 2025-01-02 12:50:21 +00:00
CHANGELOG.md release(crates): v0.44.0 (#8110) 2024-12-25 21:03:09 +08:00
README.md docs(minifier): clarify assumptions for compressor (#8404) 2025-01-10 11:37:41 +08: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); }

Terser Tests

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