Commit Graph

479 Commits

Author SHA1 Message Date
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
1318afe2b4
fix(es/minifier): Bailout regex optimization on invalid flags (#7020) 2023-03-07 11:05:04 +09:00
magic-akari
bb2486c459
fix(es/minifier): Don't create invalid property names (#7010) 2023-03-04 17:58:49 +09:00
Austaras
06cbb9002d
feat(es/minifier): Optimize calls to Boolean/Number/String/Symbol (#7006) 2023-03-04 04:14:14 +00:00
Austaras
cfeb088c37
fix(es/minifier): Don't skip expressions with side effects from seq inliner (#7007) 2023-03-04 12:32:15 +09:00
magic-akari
a27ffd2242
feat(es/minifier): Drop unused import bindings (#6967) 2023-02-21 06:22:25 +00:00
magic-akari
1dfadb8790
fix(es/minifier): Fix optimization of expressions in numeric context (#6965) 2023-02-20 05:28:28 +00:00
magic-akari
9382bda786
fix(es/minifier): Fix toFixed, toPrecision, toExponential and toString of Number (#6960) 2023-02-19 23:18:14 +09:00
Donny/강동윤
725d3fb645
fix(es/minifier): Don't skip shorthand properties from sequential inliner (#6918)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6914.
2023-02-09 03:07:31 +00:00
Donny/강동윤
951dafbc1a
fix(es/minifier): Don't break ternary with assignment in test (#6906)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6903.
2023-02-08 02:10:44 +00:00
Donny/강동윤
432dca647b
fix(es/minifier): Respect span hygiene from expr simplifier (#6899)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6896.
2023-02-07 05:14:19 +00:00
Austaras
c0e72ef64a
fix(es/minifier): Track reassign in parent scope (#6865)
**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 (#6862)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6123.
2023-01-27 14:36:12 +09: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/강동윤
21e14787c5
fix(es/minifier): Don't inline into await from sequential inliner (#6839)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6837.
2023-01-20 08:50:51 +00:00
Donny/강동윤
df702614e1
fix(es/codegen): Fix codegen of string literals with \x000 (#6838)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6836.
2023-01-20 08:08:58 +00:00
Donny/강동윤
ebce18b221
fix(es/renamer): Handle rest params correctly (#6821)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6819.
2023-01-16 06:57:16 +00:00
Donny/강동윤
8f683e3f77
feat(es/minifier): Remove noop spreads (#6803)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6788.
2023-01-13 06:55:04 +00:00
Donny/강동윤
a299fd0418
test(es/minifier): Add a test for an invalid issue (#6802)
**Related issue:**
 
 - https://github.com/vercel/next.js/discussions/30237#discussioncomment-4674405
2023-01-13 05:39:22 +00:00
Donny/강동윤
631dd7872b
feat(es/renamer): Support safari10 from the name mangler (#6801) 2023-01-13 05:00:13 +00:00
Donny/강동윤
c14540905f
fix(es/transform): Apply hygiene and resolver if minify is specified (#6793)
**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 (#6775)
**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 (#6751)
**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
Donny/강동윤
ec7e913815
fix(es/minifier): Make name mangler respect toplevel (#6774)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6418.
2023-01-10 06:42:49 +00:00
HeYunfei
8a6a1cbcf1
feat(es/minifier): Handle boolean in Evaluator (#6756)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/5953.
2023-01-06 08:15:07 +00:00
HeYunfei
a1ccc8afdf
feat(es/minifier): Make name mangler understand block scoping (#6670)
**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/강동윤
88d40e8ab8
fix(es/minifier): Fix usage counter to fix infinite loop (#6744)
**Description:**

We skip non-computed property names while checking if we can inline an expression.

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6729.
2023-01-04 04:31:12 +00:00
Donny/강동윤
206c0dbebe
fix(es/compat): Fix syntax context of async-to-generator (#6741)
**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
HeYunfei
b5d31cc2da
fix(es/utils): Fix detection of hoisting (#6738) 2023-01-03 03:12:01 +00:00
Donny/강동윤
707b1e3cd2
feat(es/minifier): Improve simplification of ?. (#6681)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6492.
2022-12-20 09:34:50 +00:00
Donny/강동윤
7e6ec8d587
fix(es/minifier): Don't inline invalid LHS into an update argument (#6680)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6641.
2022-12-20 07:45:29 +00:00
Donny/강동윤
bb9fab8d03
fix(es/minifier): Abort IIFE invoker completely on eval (#6659)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6628.
2022-12-15 07:49:58 +00:00
Donny/강동윤
7f3e6983e5
test(es/minifier): Enable size tests created from creduce (#6646) 2022-12-14 09:19:51 +00:00
Donny/강동윤
e4e4d6cf6b
fix(es/minifier): Abort sequential inliner on optional chaining (#6637)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6636.
2022-12-14 04:45:47 +00:00
Donny/강동윤
8b2e1d17e5
fix(es/minifier): Abort IIFE invoker on eval (#6478)
**Related issue:**

 - https://github.com/vercel/next.js/issues/43052.
2022-12-13 04:18:57 +00:00
Donny/강동윤
8d8f150792
test(es/minifier): Add tests for preserving top-level directives (#6545) 2022-11-30 05:46:48 +00:00
Yongwook Choi (Leo)
81224b5d67
fix(es/minifier): Don't convert a signed integer literal key to a numeric literal (#6529)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6528.
2022-11-29 07:01:30 +00:00
Donny/강동윤
9752b43f94
fix(es/minifier): Use unsafe option for arrow => method (#6521)
**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 (#6509)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6491.
2022-11-29 04:50:15 +00:00
Donny/강동윤
b394f9f1d3
fix(es/minifier): Don't drop used variables from sequential inliner (#6520)
**Related issue:**

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

 - Closes https://github.com/swc-project/swc/issues/6463.
2022-11-18 07:53:13 +00:00
HeYunfei
dabea71c44
fix(es/minifier): Preserve unused imported specifiers (#6458) 2022-11-17 00:52:19 +00:00
Donny/강동윤
bb544ba2f5
fix(es/minifier): Fix code for dropping unreachable statements (#6429)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6405.
2022-11-15 07:00:14 +00:00
Donny/강동윤
99934b09f7
fix(es/minifier): Change the default of mangle.toplevel to false (#6439) 2022-11-15 02:28:38 +00:00
Donny/강동윤
5fd7ab87b6
fix(es/minifier): Preserve op of the op-assignments in seq inliner (#6428)
**Description:**


**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6407.
2022-11-15 00:22:06 +00:00
Donny/강동윤
81a4bb304a
fix(es/compat): Fix span hygiene of function naming pass (#6345)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6344.
2022-11-14 06:03:09 +00:00
Donny/강동윤
dd797f7f15
fix(es/minifier): Don't drop an inlined parameter as a duplicate (#6293) 2022-11-02 01:57:15 +00:00
Donny/강동윤
5d52ae971e
feat(es/minifier): Implement trivial optimizations (#6256)
**Description:**

1. Evaluate `Number.toString()`.
2. Mark some terser tests as passing where our output is better.
2022-11-02 01:21:32 +00:00
Donny/강동윤
655f6744c5
fix(es/minifier): Fix infinite loop (#6300)
**Related issue:**

 - https://github.com/vercel/next.js/issues/42171.
2022-11-01 16:32:52 +00:00
Donny/강동윤
4eab2ed2fc
fix(es/minifier): Don't inline regex for IIFEs (#6283)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6279.

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
2022-10-29 00:02:32 +00:00
Donny/강동윤
0376da73c6
test(es/minifier): Add a test for ?? operator (#6282)
**Related issue:**

 - https://github.com/vercel/next.js/issues/41992.
2022-10-28 08:00:21 +00:00
Austaras
8c1ac686cb
fix(es/minifier): Don't ignore nullish coalescing (#6272) 2022-10-28 02:00:47 +00:00
Donny/강동윤
743a1aab4f
feat(es/minfiier): Compute more with sequential inliner (#6169) 2022-10-27 00:50:52 +00:00
Austaras
1cd7f617f9
feat(es/minifier): Inline a lazily initialized var if it's used once (#6237) 2022-10-26 06:02:22 +00:00
Donny/강동윤
86e265a024
feat(es/minifier): Support more statements in seqential inliner (#6248)
**Description:**

We now inline into the discriminant of a switch statement and into the initializer of for/for-in/for-of statements.
2022-10-26 13:37:10 +09:00
Donny/강동윤
01edb4fff4
test(es/minifier): Organize terser tests (#6247) 2022-10-25 05:12:30 +00:00
Donny/강동윤
ec9a80aae0
feat(es/minifier): Respect options (#6245) 2022-10-25 04:00:16 +00:00
Donny/강동윤
48bb0cc51d
fix(es/minifier): Fix collapse_vars (#6235)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6217
2022-10-23 13:43:10 +09:00
Donny/강동윤
e9d421bd95
fix(es/minifier): Preserve this in more cases (#6226)
**Related issue (if exists):**

 - Closes https://github.com/swc-project/swc/issues/6175.
 - Closes https://github.com/swc-project/swc/issues/6137.

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
2022-10-21 09:07:00 +00:00
Donny/강동윤
780b5de678
fix(es/minifier): Fix detection of direct eval (#6215) 2022-10-21 12:18:10 +09:00
Donny/강동윤
ea03ce1a82
refactor(es/minifier): Don't create invalid nodes (#6191)
**Description:**

A sequential expression should have at leat two elements.
2022-10-21 00:33:40 +00:00
Donny/강동윤
725b1185f3
test(es/minifier): Add a test for a fixed issue (#6218)
**Related issue (if exists):**

 - Closes https://github.com/swc-project/swc/issues/6217.
2022-10-20 19:26:27 +00:00
Donny/강동윤
cc848db80e
feat(es/minifier): Mark more expressions as pure (#6204) 2022-10-20 05:06:32 +00:00
Donny/강동윤
12443db39a
feat(es/minifier): Merge functions using sequential inliner (#6148) 2022-10-20 02:24:09 +00:00
Donny/강동윤
842abd4575
fix(es/minifier): Remove wrong rule (#6201)
**Related issue:**

 - https://github.com/vercel/next.js/issues/41527.
2022-10-19 02:14:38 +00:00
Donny/강동윤
f2e8f98d38
feat(es/minifier): Skip function declarations in sequential inliner (#6147) 2022-10-18 02:51:05 +00:00
Donny/강동윤
3f0fcf4fa9
feat(es/minifier): Make sequential inliner self-repeat (#6168) 2022-10-18 02:13:39 +00:00
Donny/강동윤
aec5cdacc6
fix(es/minifier): Preserve this of tagged template literals (#6165)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6146
2022-10-15 09:11:20 +00:00
Austaras
b40d486253
fix(es/minifier): Consider function body cost while inlining function (#5342) 2022-10-15 05:47:56 +00:00
Donny/강동윤
6d0ca05cb5
fix(es/minifier): Fix ordering issue of analyzer (#6150)
**Description:**

This is the groundwork for a parallel analyzer. This PR fixes the ordering issue of the analyzer so that the analyzer works identically regardless of the visit order. This patch contains some improvements because previously, we mixed `.and_modify()` and `.or_default()`.
2022-10-15 04:37:11 +00:00
Donny/강동윤
d334c6e783
feat(es/minifier): Ignore return value if a param of IIFE is not used (#6115) 2022-10-14 02:58:00 +00:00
Donny/강동윤
3d271e82a2
fix(es/minifier): Preserve return values of recursive IIFE (#6142)
**Description:**

This PR fixes the logic for dropping return values of IIFE.

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6141.
2022-10-14 09:32:56 +09:00
Donny/강동윤
ec0d6d5a0d
feat(es/minifier): Improve trivial rules (#6136) 2022-10-13 23:34:30 +00:00
Donny/강동윤
3a29bfee9b
feat(es/minifier): Change default pass limit to 3 (#6138) 2022-10-14 08:00:32 +09:00
Donny/강동윤
c37839fc62
feat(es/minifier): Swap more binary expressions (#6134) 2022-10-13 03:45:05 +00:00
Donny/강동윤
5875298377
feat(es/minifier): Merge assignments using sequential inliner (#6103) 2022-10-12 05:31:40 +00:00
Donny/강동윤
fc5d8a5d41
feat(es/minifier): Enable reduce_vars by default (#6096) 2022-10-12 04:32:15 +00:00
Donny/강동윤
66196a65be
feat(es/minifier): Inline pure array literal partially (#6099) 2022-10-12 02:29:40 +00:00
Austaras
5a23949f12
feat(es/minifier): Inline and remove vars in one pass (#6093) 2022-10-12 01:52:58 +00:00
Donny/강동윤
ad960c76c0
feat(es/minifier): Detect type of .length (#6120)
**Description:**

This PR updates minifier to detect the type of `xxx.length` if possible.
2022-10-11 23:06:58 +00:00
Donny/강동윤
6365acc9f5
test(es/minifier): Organize terser tests (#6116)
**Description:**

Our minifier is better than terser in some cases, so we don't need to match the output of terser exactly.
2022-10-11 08:25:11 +00:00
Austaras
657e5b3111
feat(es/minifier): Inline more lazily initialized vars (#6089) 2022-10-10 09:53:50 +09:00
Donny/강동윤
b0c57458c8
feat(es/minifier): Mark ref to fn as non-call in alias analyzer (#6088) 2022-10-09 09:21:54 +09:00
Donny/강동윤
9ce3df091f
feat(es/minifier): Distinguish calls in alias analyzer (#6080)
**Description:**

This PR improves the alias analyzer by distinguishing call and reference, thus reducing the number of identifiers.

---

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
2022-10-08 03:15:18 +00:00
IWANABETHATGUY
8003dc8563
feat(es/codegen): Remove the trailing comma of binding patterns (#6078) 2022-10-07 16:45:20 +09:00
Austaras
ac150c7ced
feat(es/minifier): Use usage_count in sequential inliner (#6071) 2022-10-06 17:27:34 +00:00
Austaras
c9427f1ec4
fix(es/minifier): Improve infection analysis (#6044) 2022-10-06 18:12:09 +09:00
Donny/강동윤
38df5978c1
fix(es/minifier): Mark delete as a property mutation (#6063)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6004.
2022-10-06 04:47:58 +00:00
Donny/강동윤
d65fba134d
fix(es/minifier): Fix infection analysis of sequential inliner (#6053)
**Description:**

This PR fixes the callee issue by fixing the infection analyzer.

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6047
2022-10-06 02:46:22 +00:00
Donny/강동윤
36d467e7d7
fix(es/minifier): Fix analysis of var declaration after usage (#6043)
**Description:**

`var_initialized` should be `true` even if the declaration of variable comes after its usage.

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6039.
2022-10-06 02:09:13 +00:00
Donny/강동윤
e3b55e4bcf
fix(es/minifier): Fix optimization of numeric keys (#6052)
**Description:**

We should not optimize if the key starts with `0`.

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6051.
2022-10-05 12:22:28 +00:00
Donny/강동윤
c5fb774487
fix(es/minifier): Don't skip unresolved identifiers (#6050)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6049
2022-10-05 11:44:51 +00:00
Donny/강동윤
197c4e269d
fix(es/minifier): Don't evaluate String.fromCharCode for non-ascii values (#6033) 2022-10-04 16:46:59 +09:00
Austaras
c4850997a2
feat(es/minifier): Inline vars initialized before the declaration (#6027) 2022-10-03 08:58:38 +00:00
Donny/강동윤
877936f626
feat(es/minifier): Clone trivial literals in sequential inliner (#6005)
**Description:**

As our minifier is two-pass by default, this is enough.

At the first pass, we inline all numeric literals using sequential inliner, and minifier can then inline constants correctly in the second pass.
2022-10-03 07:20:48 +00:00
Donny/강동윤
2b627524ac
feat(es/minifier): Ignore return values of ignored IIFEs (#6020)
**Description:**

As we are not using the return value of the function, we can call `ignore_return_value` on the argument of the return statements of IIFE.
2022-10-02 20:01:56 +09:00
Donny/강동윤
1aae503913
test(es/minifier): Organize terser tests (#6015) 2022-10-02 07:00:10 +00:00
Austaras
61807abf6e
feat(es/minifier): Inline function calls in more cases (#6010) 2022-10-01 18:18:45 +09:00