swc/crates/swc_ecma_minifier/tests/fixture/projects/react
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
..
.6 refactor(es/minifier): Make rust-analyzer fast, really (#4746) 2022-05-23 16:16:05 +09:00
1 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
2 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
3 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
4 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
5 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
7 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
8 fix(es/minifier): Don't skip unresolved identifiers (#6050) 2022-10-05 11:44:51 +00:00
9 fix(es/minifier): Mark all function params as potential property mutation (#7409) 2023-05-18 01:19:17 +00:00
10 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
11 fix(es/minifier): Don't skip unresolved identifiers (#6050) 2022-10-05 11:44:51 +00:00
12 feat(es/minifier): Make sequential inliner self-repeat (#6168) 2022-10-18 02:13:39 +00:00
13 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
14 fix(es/minifier): Don't skip unresolved identifiers (#6050) 2022-10-05 11:44:51 +00:00
15 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00
16 test(es/minifier): Remove mangle-only snapshots (#5979) 2022-09-28 21:35:52 +09:00