mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
Follow up from https://github.com/oxc-project/oxc/pull/8543#discussion_r1918592423 > I agree. https://github.com/oxc-project/backlog/issues/155 > Originally we were considering some form of interning and reference-counting, so we didn't make it Copy to leave the door open for that. But now all strings are stored in the arena anyway, so even if we did decide to intern strings, reference-counting would be irrelevant - our bump allocator doesn't allow freeing individual allocations anyway. Most of the changes are done automatically by `just fix` (`cargo clippy --fix` && `cargo fmt --all`). See the commit list for the manual edits. |
||
|---|---|---|
| .. | ||
| examples | ||
| src | ||
| tests | ||
| Cargo.toml | ||
| CHANGELOG.md | ||
| README.md | ||
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.allis 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:
withstatement is not used- Examples that breaks this assumption:
with (Math) { console.log(PI); }
- Examples that breaks this assumption:
- 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') }
- Examples that breaks this assumption:
Terser Tests
The fixtures are copied from https://github.com/terser/terser/tree/v5.9.0/test/compress