#javascript #minify #typescript #linter #parser

oxc_minifier

A collection of JavaScript tools written in Rust

97 releases (58 breaking)

Uses new Rust 2024

new 0.58.1 Mar 13, 2025
0.57.0 Mar 11, 2025
0.44.0 Dec 25, 2024
0.38.0 Nov 26, 2024
0.1.0 Jul 27, 2023

#976 in Programming languages

Download history 1222/week @ 2024-11-22 917/week @ 2024-11-29 1438/week @ 2024-12-06 1084/week @ 2024-12-13 1213/week @ 2024-12-20 1204/week @ 2024-12-27 347/week @ 2025-01-03 899/week @ 2025-01-10 761/week @ 2025-01-17 930/week @ 2025-01-24 1159/week @ 2025-01-31 4800/week @ 2025-02-07 4782/week @ 2025-02-14 2771/week @ 2025-02-21 1479/week @ 2025-02-28 2311/week @ 2025-03-07

12,365 downloads per month
Used in 20 crates (2 directly)

MIT license

5.5MB
111K SLoC

Minifier

A JavaScript minifier has three components:

  1. compressor
  2. mangler
  3. printer

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.

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.

Printer

The printer is responsible for removing whitespace from the source text.

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 {}
  • The code does not rely on the name property of Function or Class
    • Examples that breaks this assumption: function fn() {}; console.log(f.name === 'fn')
  • 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); }
  • .toString(), .valueOf(), [Symbol.toPrimitive]() are side-effect free
    • Examples that breaks this assumption: { toString() { console.log('sideeffect') } }
  • 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') }
  • Invalid super class error does not happen
    • Examples that breaks this assumption: const v = []; class A extends v {}

Terser Tests

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

Dependencies

~9.5MB
~170K SLoC