Commit Graph

18 Commits

Author SHA1 Message Date
Donny/강동윤
3873f58499
fix(es/minifier): Mark args of news as references (#7743)
**Related issue:**

 - Closes #7739.
2023-08-03 07:02:15 +09:00
Donny/강동윤
f901b417d1
fix(es/minifier): Do not drop used properties (#7702)
**Related issue:**

 - Closes #7700.
 - Closes #7710.
2023-07-28 16:57:07 +00:00
Austaras
9893bd2d43
refactor(es/minifier): Respect toplevel and module options (#7671) 2023-07-20 11:35:08 +09:00
Austaras
04b0f6d823
feat(es/minifier): Drop recursively used var declaration (#7649) 2023-07-15 05:54:34 +09:00
Donny/강동윤
b34f1adbcc
build(cargo): Update rustc to 2023-07-03 (#7623) 2023-07-05 03:50:43 +00:00
Donny/강동윤
47d2edd4dc
feat(es/minifier): Drop unused properties (#7534)
**Related issue:**

 - Closes #7472.
2023-07-04 05:11:33 +00:00
Donny/강동윤
a685c88c61
fix(es/minifier): Don't drop assignments to unused top-level variables (#7581)
**Related issue:**

 - Closes #7568
2023-06-27 15:24:06 +00:00
Donny/강동윤
398e922ca0
feat(es/minifier): Inline constants even if they are exported (#7583)
**Related issue:**

 - Closes #7575.
2023-06-27 02:14:09 +00:00
Donny/강동윤
07a858030c
feat(es/minifier): Enable hoist_props by default (#7535) 2023-06-21 18:38:35 +09:00
Austaras
7f9f0b8bce
fix(es/minifier): Infect mutation when assigning a property (#7503) 2023-06-08 04:13:42 +00:00
Austaras
0cd2b61b05
feat(es/minifier): Inline for loop variables (#7445) 2023-05-25 03:59:02 +00:00
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
Donny/강동윤
73bc29eeb0
fix(es/minifier): Don't remove used var decl (#7200)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/7194.
2023-04-05 04:35:37 +00:00
Donny/강동윤
610e1bb581
fix(es/minifier): Don't inline into arrow heads (#7099)
**Related issue:**

 - https://github.com/vercel/next.js/issues/47005
2023-03-22 02:24:13 +00:00
Donny/강동윤
a9fe1d2d22
perf(es/ast): Shrink size of Expr (#7041)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/7019.
2023-03-09 13:34:11 +00:00
Austaras
55225cb994
refactor(es/minifier): Merge cond_init with reassigned (#6850)
**Description:**

And optimize the following situation
```js
export function genElement(el, state) {
    if ('slot' === el.tag) return el1 = el, genChildren(el1);
    if (el.component) {
        var el1
        return 999;
    }
}
```
which rarely happens in hand written JS, but is often generated by swc merge variable pass.
2023-01-26 10:17:33 +09:00
Donny/강동윤
06770cff04
fix(es/minifier): Make AST compressor respect toplevel (#6775)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/4386.
2023-01-11 07:04:20 +00:00
Alex Kirszenberg
e1d01d8b7a
feat(es/analyzer): Extract the analyzer from the minifier to a separate crate (#6586) 2022-12-07 11:53:49 +00:00