Austaras
40d2bf7ec3
fix(es/minifier): Prevent inlining vars assigned outside current function scope ( #7414 )
...
**Related issue:**
- Closes #7412 .
2023-05-19 13:35:50 +09: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/강동윤
1dced17998
fix(es/minifier): Fix remapping of vars upon inlining ( #7362 )
...
**Related issue:**
- Closes #7331 .
2023-05-10 03:31:15 +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
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
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/강동윤
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
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/강동윤
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/강동윤
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
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/강동윤
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/강동윤
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/강동윤
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/강동윤
cc848db80e
feat(es/minifier): Mark more expressions as pure ( #6204 )
2022-10-20 05:06:32 +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
Austaras
b40d486253
fix(es/minifier): Consider function body cost while inlining function ( #5342 )
2022-10-15 05:47:56 +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/강동윤
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/강동윤
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
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/강동윤
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/강동윤
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
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
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
Austaras
1a11cfd46f
feat(es/minifier): Improve fn-local analysis for better inlining ( #5955 )
2022-09-29 14:16:28 +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