mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
docs(minifier): add Function.prototype.toString assumption (#19758)
Added `Function.prototype.toString` assumption to the docs as I think we assumed this as well.
This commit is contained in:
1 file changed
+11
@@ -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
|
||||
|
||||
Reference in new issue
Block a user