oxc/crates/oxc_minifier
branchseer ac4f98e376
refactor(span): derive Copy on Atom (#8596)
Follow up from
https://github.com/oxc-project/oxc/pull/8543#discussion_r1918592423

> I agree. https://github.com/oxc-project/backlog/issues/155

> Originally we were considering some form of interning and
reference-counting, so we didn't make it Copy to leave the door open for
that. But now all strings are stored in the arena anyway, so even if we
did decide to intern strings, reference-counting would be irrelevant -
our bump allocator doesn't allow freeing individual allocations anyway.

Most of the changes are done automatically by `just fix` (`cargo clippy
--fix` && `cargo fmt --all`). See the commit list for the manual edits.
2025-01-19 16:14:23 +08:00
..
examples feat(napi/minify): implement napi (#8478) 2025-01-14 08:55:55 +00:00
src refactor(span): derive Copy on Atom (#8596) 2025-01-19 16:14:23 +08:00
tests fix(minifier): fix dce shadowed undefined (#8582) 2025-01-18 09:04:28 +00:00
Cargo.toml release(crates): v0.47.1 (#8593) 2025-01-19 09:44:29 +08:00
CHANGELOG.md release(crates): v0.47.1 (#8593) 2025-01-19 09:44:29 +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