swc/crates/swc_ecma_minifier/tests/terser/compress/pure_getters
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
..
chained test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
collapse_rhs_call test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
collapse_rhs_false test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
collapse_rhs_lhs test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
collapse_rhs_setter test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
collapse_rhs_strict test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
collapse_rhs_true test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
collapse_vars_1_false test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
collapse_vars_1_strict test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
collapse_vars_1_true test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
collapse_vars_2_false test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
collapse_vars_2_strict test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
collapse_vars_2_true test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
impure_getter_1 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
impure_getter_2 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_2110_1 test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
issue_2110_2 test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
issue_2265_1 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_2265_2 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_2265_3 test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
issue_2265_4 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_2313_1 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_2313_2 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_2313_3 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_2313_4 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_2313_5 test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
issue_2313_6 test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
issue_2313_7 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_2678 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_2838 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_2938_1 test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
issue_2938_2 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
issue_2938_3 test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
issue_2938_4 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
set_immutable_1 test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
set_immutable_2 fix(es/minifier): Mark all function params as potential property mutation (#7409) 2023-05-18 01:19:17 +00:00
set_immutable_3 test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
set_immutable_4 fix(es/minifier): Mark all function params as potential property mutation (#7409) 2023-05-18 01:19:17 +00:00
set_immutable_5 test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
set_immutable_6 test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
set_mutable_1 test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
set_mutable_2 test(es/minifier): Remove analysis snapshot (#5939) 2022-09-23 13:14:42 +09:00
strict test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
strict_reduce_vars test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
unsafe test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
unsafe_reduce_vars test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00