#javascript #minify #typescript #linter #parser

oxc_minifier

A collection of JavaScript tools written in Rust

76 releases (46 breaking)

new 0.46.0 Jan 14, 2025
0.44.0 Dec 25, 2024
0.38.0 Nov 26, 2024
0.22.1 Jul 28, 2024
0.1.0 Jul 27, 2023

#1348 in Programming languages

Download history 2031/week @ 2024-09-27 1003/week @ 2024-10-04 860/week @ 2024-10-11 1255/week @ 2024-10-18 779/week @ 2024-10-25 1185/week @ 2024-11-01 848/week @ 2024-11-08 1124/week @ 2024-11-15 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 829/week @ 2025-01-10

3,713 downloads per month
Used in oxc

MIT license

4.5MB
103K 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

~10MB
~171K SLoC