Skip to content

Commit

Permalink
docs(minifier): clarify assumptions for compressor (#8404)
Browse files Browse the repository at this point in the history
Listed the assumptions that the compressor probably makes.
  • Loading branch information
sapphi-red authored Jan 10, 2025
1 parent 8d2176e commit aaa009d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/oxc_minifier/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ The printer is also responsible for printing out the shortened variable names.
The compressor is responsible for rewriting statements and expressions for minimal text output.
[Terser](https://github.com/terser/terser) is a good place to start for learning the fundamentals.

### Assumptions

- [Properties of the global object defined in the ECMAScript spec](https://tc39.es/ecma262/multipage/global-object.html#sec-global-object) 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`](https://tc39.es/ecma262/multipage/additional-ecmascript-features-for-web-browsers.html#sec-IsHTMLDDA-internal-slot) 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

0 comments on commit aaa009d

Please sign in to comment.