swc/crates/swc_ecma_minifier/tests/terser/compress/issue_281
Austaras 5dbbbea2ef
fix(es/minifier): Mark all function params as potential property mutation (#7409)
**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.
2023-05-18 01:19:17 +00:00
..
collapse_vars_constants test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
drop_fargs feat(es/minifier): Respect options (#6245) 2022-10-25 04:00:16 +00:00
inner_var_for_in_1 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_1254_negate_iife_nested test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_1254_negate_iife_true test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_1288_side_effects test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_1595_3 fix(es/minifier): Mark all function params as potential property mutation (#7409) 2023-05-18 01:19:17 +00:00
issue_1758 test(es/minifier): Enable more terser tests (#7396) 2023-05-16 03:21:08 +00:00
keep_fargs feat(es/minifier): Respect options (#6245) 2022-10-25 04:00:16 +00:00
modified test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
negate_iife_3 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
negate_iife_3_off test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
negate_iife_4 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
negate_iife_5 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
negate_iife_5_off test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
negate_iife_issue_1073 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
pure_annotation_1 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
pure_annotation_2 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
ref_scope test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
safe_undefined test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
wrap_iife test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
wrap_iife_in_expression test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
wrap_iife_in_return_call test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00