#javascript #minify #typescript #linter #parser

oxc_minifier

A collection of JavaScript tools written in Rust

82 releases (49 breaking)

new 0.49.0 Feb 10, 2025
0.48.1 Jan 26, 2025
0.44.0 Dec 25, 2024
0.38.0 Nov 26, 2024
0.1.0 Jul 27, 2023

#1381 in Programming languages

Download history 1144/week @ 2024-10-22 854/week @ 2024-10-29 1132/week @ 2024-11-05 900/week @ 2024-11-12 1041/week @ 2024-11-19 946/week @ 2024-11-26 1186/week @ 2024-12-03 1483/week @ 2024-12-10 1026/week @ 2024-12-17 1651/week @ 2024-12-24 448/week @ 2024-12-31 706/week @ 2025-01-07 985/week @ 2025-01-14 811/week @ 2025-01-21 1074/week @ 2025-01-28 875/week @ 2025-02-04

3,861 downloads per month
Used in 16 crates (via oxc)

MIT license

5MB
105K SLoC

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 {}
  • 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') }

Terser Tests

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

Dependencies

~9.5MB
~169K SLoC