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
3,961 downloads per month
Used in oxc
5MB
105K
SLoC
Minifier
A JavaScript minifier has three components:
- printer
- mangler
- 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 {}
- Examples of properties:
document.all
is not used or behaves as a normal object- Examples that breaks this assumption:
console.log(typeof document.all === 'undefined')
- Examples that breaks this assumption:
- TDZ violation does not happen
- Examples that breaks this assumption:
(() => { console.log(v); let v; })()
- Examples that breaks this assumption:
with
statement is not used- Examples that breaks this assumption:
with (Math) { console.log(PI); }
- Examples that breaks this assumption:
Terser Tests
The fixtures are copied from https://github.com/terser/terser/tree/v5.9.0/test/compress
Dependencies
~9.5MB
~170K SLoC