docs(minifier): clarify assumptions for compressor (#8404)

Listed the assumptions that the compressor probably makes.
This commit is contained in:
翠 / green 2025-01-10 12:37:41 +09:00 committed by GitHub
parent 8d2176e2e1
commit aaa009dd4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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. 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. [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 ## Terser Tests
The fixtures are copied from https://github.com/terser/terser/tree/v5.9.0/test/compress The fixtures are copied from https://github.com/terser/terser/tree/v5.9.0/test/compress