From 1b392de6bb56b428ccd9e8c6220dfccf22ce023d Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Fri, 27 Feb 2026 03:40:32 +0000 Subject: [PATCH] docs(minifier): add `Function.prototype.toString` assumption (#19758) Added `Function.prototype.toString` assumption to the docs as I think we assumed this as well. --- crates/oxc_minifier/docs/ASSUMPTIONS.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/oxc_minifier/docs/ASSUMPTIONS.md b/crates/oxc_minifier/docs/ASSUMPTIONS.md index 6def0c0dfefb3..8c105aca9c5f4 100644 --- a/crates/oxc_minifier/docs/ASSUMPTIONS.md +++ b/crates/oxc_minifier/docs/ASSUMPTIONS.md @@ -107,6 +107,17 @@ Accessing a global variable named `arguments` does not have a side effect. We in console.log(arguments); // ReferenceError: arguments is not defined ``` +### `Function.prototype.toString` is not relied on + +Code does not depend on [`Function.prototype.toString()`](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-function.prototype.tostring) returning specific source text. Minification renames variables and parameters, simplifies expressions (`true` → `!0`), restructures statements (fusing with the comma operator, converting `while` to `for`), removes whitespace, and may eliminate function bodies entirely (e.g. IIFE inlining). All of these change the string returned by `.toString()`. + +```javascript +const serialize = (fn) => fn.toString(); +serialize((x) => { + return x * 2; +}); // Relied on to contain "return" +``` + ## Optional Assumptions ### No Reliance on Function.prototype.name