mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 06:36:08 +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. |
||
---|---|---|
.. | ||
collapse_vars_constants | ||
drop_fargs | ||
inner_var_for_in_1 | ||
issue_1254_negate_iife_nested | ||
issue_1254_negate_iife_true | ||
issue_1288_side_effects | ||
issue_1595_3 | ||
issue_1758 | ||
keep_fargs | ||
modified | ||
negate_iife_3 | ||
negate_iife_3_off | ||
negate_iife_4 | ||
negate_iife_5 | ||
negate_iife_5_off | ||
negate_iife_issue_1073 | ||
pure_annotation_1 | ||
pure_annotation_2 | ||
ref_scope | ||
safe_undefined | ||
wrap_iife | ||
wrap_iife_in_expression | ||
wrap_iife_in_return_call |