Commit Graph

134 Commits

Author SHA1 Message Date
Donny/강동윤
6d9763e8c0
fix(es/renamer): Don't use symbols used by declarations if eval exists (#7116)
**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
Anders Kaseorg
493a4f7042
fix(es/minifier): Remove wrong optimization of new RegExp(…) (#7091) 2023-03-17 03:22:02 +00:00
Donny/강동윤
86295ba8f2
fix(es/minifier): Preserve delete of unresolved variables (#7072)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/7045.
2023-03-15 02:31:08 +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
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/강동윤
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/강동윤
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/강동윤
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/강동윤
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/강동윤
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/강동윤
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/강동윤
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
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/강동윤
c37839fc62
feat(es/minifier): Swap more binary expressions (#6134) 2022-10-13 03:45:05 +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
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
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/강동윤
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
Austaras
c4850997a2
feat(es/minifier): Inline vars initialized before the declaration (#6027) 2022-10-03 08:58:38 +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
Austaras
61807abf6e
feat(es/minifier): Inline function calls in more cases (#6010) 2022-10-01 18:18:45 +09:00
Donny/강동윤
286334c4d0
feat(es/minifier): Drop vars from sequential inliner (#5993)
**Description:**

This PR renames `CloningMultiReplacer` to `Finalizer` and makes it handle the removal of unused variables. Also, this PR improves the sequential inliner so we can drop variables within a single pass.
2022-09-30 09:43:31 +00:00
Donny/강동윤
aeb7f300a8
feat(es/minifier): Invoke sequential inliner for inlined IIFEs (#5991)
**Description:**

Inlined IIFEs have the exact pattern sequential inliner wants, so it's good to invoke it.
2022-09-29 11:03:06 +00:00
Donny/강동윤
f8358fbe2b
fix(es/minifier): Remove wrong variable joiner pass (#5992)
**Description:**

We had two passes for joining variables. This PR removes one in the full optimizer, which is wrong.

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/5989.
2022-09-29 19:11:18 +09:00
Donny/강동윤
c411e5d552
feat(es/minifier): Drop more variables while invoking IIFE (#5987) 2022-09-29 02:15:56 +00:00
Donny/강동윤
0cfc724018
test(es/minifier): Add tests for benchmark files (#5986) 2022-09-29 09:41:13 +09:00
Donny/강동윤
0e69890764
feat(es/minifier): Evaluate more literals in comparison (#5976)
**Description:**

I'll fix the performance issue with a follow-up PR.

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/4415.
2022-09-28 08:07:55 +00:00
Donny/강동윤
dcd516d2bd
feat(es/minifier): Ignore more expressions in sequential inliner (#5961)
**Description:**

We can skip **member access** to `console` as it does not have any side effects.
2022-09-27 07:45:44 +00:00
Donny/강동윤
97647861bf
fix(es/minifier): Track aliasing via assignments (#5940) 2022-09-23 14:22:41 +09:00
Donny/강동윤
e9c704182b
feat(es/minifier): Improve analysis of reassignments (#5931) 2022-09-22 10:22:18 +00:00
Donny/강동윤
e303f7e853
fix(es/minifier): Fix analysis of assignments (#5924)
**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/5910
2022-09-21 11:33:25 +00:00
Donny/강동윤
1df72430a5
perf(es/minifier): Invoke DCE only before the first compression (#5907)
**Description:**

Invoke DCE only before the first compression. I verified that this patch does not affect the compression rate of the real-world inputs greatly.
2022-09-20 15:41:26 +09:00
Donny/강동윤
4e656af1ec
feat(es/minifier): Drop variable from the sequential inliner (#5896)
**Description:**

We now drop variable declarations if we are going to eliminate the only usage.

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/5693.
2022-09-19 07:40:04 +00:00
IWANABETHATGUY
7d6d04b421
fix(es/codegen): Drop the last comma in an array literal (#5877)
**Description:**

Drop the last comma in an array literal.

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/5692.
2022-09-16 15:48:28 +09:00
Austaras
63fb0c4ad3
feat(es/minifier): Move assign with seq init into seq (#5847) 2022-09-14 12:57:18 +00:00
Austaras
8567a38c4a
feat(es/minifier): Extend inlining of identifiers to multi-usage (#5832) 2022-09-13 03:52:47 +00:00
Austaras
ee26337a25
feat(es/minifier): Inline lazily initialized variables (#5737)
Safety:

For a function-local variable, an expression with side-effects would be a call, including an indirect one with a member expression.

 - If the call is function-local, it will be analyzed by the analyzer and inliner will not work.
 - If the call is not a function-local one, it cannot modify the local variable.
2022-09-08 08:07:43 +00:00
Austaras
90852f5aa6
fix(es/minifier): Fix analysis of assignments and classes (#5770) 2022-09-07 03:51:42 +00:00
Donny/강동윤
6ba6da62d7
perf(es/minifier): Make dead branch remover parallel (#5734) 2022-09-04 07:33:26 +00:00
Austaras
5b2d024788
feat(es/minifier): Relax requirement for IIFE invokation (#5721) 2022-09-03 07:33:31 +00:00