mirror of
https://github.com/swc-project/swc.git
synced 2024-12-30 00:52:29 +03:00
5dbbbea2ef
**Description:** This issue is more severe than I originally thought. It raises not in array indexing, but in function calls and property mutation. We should treat all function arguments as potentially be property mutated, otherwise following example ```js class A { a = 1 toString() { return this.a } } const a = new A() function foo(x) { x.a++ } const b = a + 1 foo(a) console.log(b) ``` would be error(It should log 2, but logs 3 after compress). As the result, massive regressions is unavoidable, since some of these optimizations may indeed cause error. Part of them can be mitigated with following optimization -- allow inline of ident even if its original value is mutated. Consider ```js export function foo(x) { const y = x x.a = 1 y.b = 2 } ``` If x is a primitive value, all mutations to its properties are ignored; if x is a object, then y refers to the same object no matter what mutation is performed. And there's still room for more, currently following code ```js export function foo(x) { const y = Math.floor(x); g(y); } ``` But I'd rather do it in a separate PR. **Related issue:** - Closes #7402. |
||
---|---|---|
.. | ||
input.js | ||
output.js |