Commit Graph

181 Commits

Author SHA1 Message Date
Austaras
04b0f6d823
feat(es/minifier): Drop recursively used var declaration () 2023-07-15 05:54:34 +09:00
Austaras
4f866de878
fix(es/minifier): Add usage to inlined ident eagerly ()
**Related issue:**

 - Closes .
2023-07-04 06:23:49 +00:00
Austaras
ff1ad95b59
feat(es/minifier): Compress common sub expressions in sequences () 2023-07-04 05:47:37 +00:00
Donny/강동윤
47d2edd4dc
feat(es/minifier): Drop unused properties ()
**Related issue:**

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

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

 - Closes .
2023-06-27 02:14:09 +00:00
Donny/강동윤
07a858030c
feat(es/minifier): Enable hoist_props by default () 2023-06-21 18:38:35 +09:00
Donny/강동윤
aa83584634
refactor(es/ast): Reimplement optional chaining ()
**Related issue:**

 - Closes .
 - Closes .
2023-06-12 06:47:40 +00:00
Austaras
7f9f0b8bce
fix(es/minifier): Infect mutation when assigning a property () 2023-06-08 04:13:42 +00:00
David Sherret
064bcf4854
fix(es/codegen): Remove extra spaces in AssignPatProp and KeyValuePatProp ()
Co-authored-by: Donny/강동윤 <kdy1997.dev@gmail.com>
2023-06-07 05:08:35 +00:00
Austaras
62075faeaa
feat(es/minifier): Remove unused labels () 2023-06-07 04:23:40 +00:00
Donny/강동윤
e506635f74
fix(es/minifier): Don't generate generator arrows ()
**Related issue:**

 - Closes .
2023-05-31 01:57:13 +00:00
Austaras
40d2bf7ec3
fix(es/minifier): Prevent inlining vars assigned outside current function scope ()
**Related issue:**

 - Closes .
2023-05-19 13:35:50 +09:00
Austaras
5dbbbea2ef
fix(es/minifier): Mark all function params as potential property mutation ()
**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 .
2023-05-18 01:19:17 +00:00
Donny/강동윤
1dced17998
fix(es/minifier): Fix remapping of vars upon inlining ()
**Related issue:**

 - Closes .
2023-05-10 03:31:15 +00:00
Donny/강동윤
0aab90c005
fix(es/minifier): Fix a inliner bug related to Script ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/7287.
2023-04-19 07:22:48 +00:00
Donny/강동윤
a44fea1ec8
fix(es/minifier): Fix handling of optional chaining when hoist_props is enabled ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/7228.
2023-04-13 03:23:29 +00:00
Donny/강동윤
559d1202bc
feat(es/minifier): Support PURE comment of seq exprs ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/7241.
2023-04-11 04:48:11 +00:00
Donny/강동윤
73bc29eeb0
fix(es/minifier): Don't remove used var decl ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/7194.
2023-04-05 04:35:37 +00:00
Donny/강동윤
0259a7465f
build(cargo): Update rustc to nightly-2023-03-20 ()
**Description:**

This PR also updates `rkyv` to `=0.7.40`.

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6807.
2023-03-30 08:06:02 +00:00
Donny/강동윤
12546c853a
build(cargo): Revert rustc upgrade ()
**Description:**

The `rkyv` bug is not fixed.
2023-03-29 17:48:45 +09:00
Donny/강동윤
e445502072
build(cargo): Update rustc to nightly-2023-03-28 ()
**Description:**

This PR also updates `rkyv` to `=0.7.40`.

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6807.
2023-03-29 06:24:19 +00:00
Donny/강동윤
6d9763e8c0
fix(es/renamer): Don't use symbols used by declarations if eval exists ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6971.
 - Closes https://github.com/swc-project/swc/issues/7094.
2023-03-22 06:31:43 +00:00
Donny/강동윤
6a570a334c
fix(es/ast): Fix EqIgnoreSpan impl of Number ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/7111.
2023-03-21 08:46:22 +00:00
Anders Kaseorg
493a4f7042
fix(es/minifier): Remove wrong optimization of new RegExp(…) () 2023-03-17 03:22:02 +00:00
Donny/강동윤
86295ba8f2
fix(es/minifier): Preserve delete of unresolved variables ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/7045.
2023-03-15 02:31:08 +00:00
Austaras
1318afe2b4
fix(es/minifier): Bailout regex optimization on invalid flags () 2023-03-07 11:05:04 +09:00
magic-akari
bb2486c459
fix(es/minifier): Don't create invalid property names () 2023-03-04 17:58:49 +09:00
Austaras
06cbb9002d
feat(es/minifier): Optimize calls to Boolean/Number/String/Symbol () 2023-03-04 04:14:14 +00:00
Austaras
cfeb088c37
fix(es/minifier): Don't skip expressions with side effects from seq inliner () 2023-03-04 12:32:15 +09:00
magic-akari
a27ffd2242
feat(es/minifier): Drop unused import bindings () 2023-02-21 06:22:25 +00:00
magic-akari
1dfadb8790
fix(es/minifier): Fix optimization of expressions in numeric context () 2023-02-20 05:28:28 +00:00
magic-akari
9382bda786
fix(es/minifier): Fix toFixed, toPrecision, toExponential and toString of Number () 2023-02-19 23:18:14 +09:00
Austaras
c0e72ef64a
fix(es/minifier): Track reassign in parent scope ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6864.
2023-01-28 17:19:19 +00:00
Donny/강동윤
d1687d8e01
feat(es/minifier): Improve compatibility of arrows with terser ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6123.
2023-01-27 14:36:12 +09:00
Donny/강동윤
21e14787c5
fix(es/minifier): Don't inline into await from sequential inliner ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6837.
2023-01-20 08:50:51 +00:00
Donny/강동윤
c14540905f
fix(es/transform): Apply hygiene and resolver if minify is specified ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6791.
2023-01-12 07:29:28 +00:00
Donny/강동윤
06770cff04
fix(es/minifier): Make AST compressor respect toplevel ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/4386.
2023-01-11 07:04:20 +00:00
Donny/강동윤
336b1d8b4d
fix(es/minifier): Don't inline conditionally initialized vars ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6750.
 - Closes https://github.com/swc-project/swc/issues/6780.
2023-01-11 06:01:56 +00:00
HeYunfei
a1ccc8afdf
feat(es/minifier): Make name mangler understand block scoping ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/5090.
 - Closes https://github.com/swc-project/swc/issues/5766.
2023-01-06 03:14:10 +00:00
Donny/강동윤
206c0dbebe
fix(es/compat): Fix syntax context of async-to-generator ()
**Description:**

Previously, the `async-to-generator` produced invalid AST, in the aspect of span hygiene.

[Playground](https://play.swc.rs/?version=1.3.24&code=H4sIAAAAAAAAAz1MbQqAIBT77yn2UyG6gNQJuoSZRCAa7xkk4d1TicZgH7C5%2B4yUYGPgBE7ZuyWazREmSIVpxiMAcumi0C3ANZxyvQ6%2Fqa8CehxjaGNpOAcLaWjn%2F6KhKN1dGaoULSpfHPTdxn8AAAA%3D&config=H4sIAAAAAAAAA0WOSwrDMAxE76K1F22hXfgE3fQQxlWCi39ICsQY3z12cMlOjObNTIUfW9AVsiFGGheXKGYHDVIysiWXBRQId2kxnrEpwF2QovFv9BmJQQtt2D2GVpROIj9u92enfEqMk1MQXHRLGR02hUzIfL1MXP3f2XpFSN9tCPWccWa%2BoF0Zk3P8mcYxoR3Kj7IYzwAAAA%3D%3D).
It generate two bindings for `args` so it's invalid.


**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6730.
2023-01-03 09:45:03 +00:00
Donny/강동윤
707b1e3cd2
feat(es/minifier): Improve simplification of ?. ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6492.
2022-12-20 09:34:50 +00:00
Donny/강동윤
bb9fab8d03
fix(es/minifier): Abort IIFE invoker completely on eval ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6628.
2022-12-15 07:49:58 +00:00
Donny/강동윤
e4e4d6cf6b
fix(es/minifier): Abort sequential inliner on optional chaining ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6636.
2022-12-14 04:45:47 +00:00
Donny/강동윤
8d8f150792
test(es/minifier): Add tests for preserving top-level directives () 2022-11-30 05:46:48 +00:00
Donny/강동윤
9752b43f94
fix(es/minifier): Use unsafe option for arrow => method ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6504.
 - https://github.com/vercel/next.js/issues/43208.
2022-11-29 05:23:55 +00:00
Donny/강동윤
27ae59e77b
fix(es/minifier): Make sequential inliner respect resolution order ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6491.
2022-11-29 04:50:15 +00:00
HeYunfei
8d906b45e5
fix(es/minifier): Preserve classes with side effects in static fields () 2022-11-24 09:43:00 +00:00
HeYunfei
9154bbc111
fix(es/minifier): Avoid dropping statements which has side-effects () 2022-11-20 00:26:52 +00:00
Donny/강동윤
15ad2c2568
fix(es/minifier): Abort inliner on fn declarations used multiple time ()
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6463.
2022-11-18 07:53:13 +00:00