From aaa009dd4d1fa02d8a62509f181eae80e15a7704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Fri, 10 Jan 2025 12:37:41 +0900 Subject: [PATCH] docs(minifier): clarify assumptions for compressor (#8404) Listed the assumptions that the compressor probably makes. --- crates/oxc_minifier/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/oxc_minifier/README.md b/crates/oxc_minifier/README.md index 68b504ed7..e88a31d7e 100644 --- a/crates/oxc_minifier/README.md +++ b/crates/oxc_minifier/README.md @@ -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