#javascript #minify #typescript #linter #parser

oxc_minifier

A collection of JavaScript tools written in Rust

75 releases (45 breaking)

new 0.45.0 Jan 11, 2025
0.44.0 Dec 25, 2024
0.43.0 Dec 21, 2024
0.38.0 Nov 26, 2024
0.1.0 Jul 27, 2023

#1340 in Programming languages

Download history 3169/week @ 2024-09-21 1462/week @ 2024-09-28 1074/week @ 2024-10-05 856/week @ 2024-10-12 1185/week @ 2024-10-19 822/week @ 2024-10-26 1134/week @ 2024-11-02 944/week @ 2024-11-09 1160/week @ 2024-11-16 1091/week @ 2024-11-23 996/week @ 2024-11-30 1549/week @ 2024-12-07 886/week @ 2024-12-14 1267/week @ 2024-12-21 1131/week @ 2024-12-28 431/week @ 2025-01-04

3,961 downloads per month
Used in 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 {}
  • 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

Dependencies

~9.5MB
~170K SLoC