Austaras
bb02cdd26e
refactor(es/minifier): Simplify analyzer context ( #8164 )
2023-10-27 18:16:00 +00:00
Donny/강동윤
35601e4dcb
fix(es/minifier): Abort function inliner if keep_fnames
is true
( #8145 )
...
**Related issue:**
- https://github.com/vercel/next.js/issues/56408
2023-10-19 20:20:54 +00:00
Austaras
4f67794223
feat(es/minifier): Inline into the arguments of new
using seq inliner ( #8127 )
2023-10-18 03:07:14 +00:00
Donny/강동윤
94bb42e294
fix(es/minifier): Don't inline functions if keep_fnames
is enabled ( #8093 )
...
**Related issue:**
- https://github.com/vercel/next.js/issues/56550
2023-10-12 00:39:19 +00:00
Donny/강동윤
b3d3a7bc73
fix(es/minifier): Do not inline into a template literal with sequential inliner ( #7971 )
...
**Related issue:**
- Closes #7969 .
2023-09-20 06:57:03 +00:00
Donny/강동윤
7fe01e64dd
fix(es/minifier): Don't inline properties if the var is not fn-local
( #7839 )
...
**Related issue:**
- https://github.com/vercel/next.js/issues/54192 .
2023-08-22 11:04:15 +09:00
Austaras
f8ca366cc1
fix(es/minifier): Abort seq inliner if var is not fn_local or reassigned ( #7804 )
...
**Description:**
It turns out that the original implementation of `infect`is incomplete
because it cannot cover function param, and the new implementation
introduced in #7772 is redundant because what
[terser](https://github.com/terser/terser/blob/master/lib/compress/tighten-body.js#L909C18-L909C28 )
do is basically checking `fn_local`
**Related issue:**
- Closes #7784
2023-08-17 05:15:59 +00:00
Austaras
ef8d12154d
fix(es/minifier): Abort seq inliner if a same var is defined in outer scope ( #7772 )
...
**Description:**
The algorithm here is directly copied from terser, I don't if it's correct or can be improved, but it does fix the issue.
**Related issue:**
- Closes #7749
2023-08-09 20:01:59 +00: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
Donny/강동윤
6be1f7075d
fix(es/minifier): Fix a bug about eval
of name mangler ( #7615 )
...
**Description:**
- Repro: https://github.com/avitorio/swcminify-debug
**Related issue:**
- https://github.com/vercel/next.js/discussions/30237#discussioncomment-6288339
2023-07-18 01:09:00 +00:00
Austaras
ff1ad95b59
feat(es/minifier): Compress common sub expressions in sequences ( #7587 )
2023-07-04 05:47:37 +00:00
Donny/강동윤
47d2edd4dc
feat(es/minifier): Drop unused properties ( #7534 )
...
**Related issue:**
- Closes #7472 .
2023-07-04 05:11:33 +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
David Sherret
064bcf4854
fix(es/codegen): Remove extra spaces in AssignPatProp
and KeyValuePatProp
( #7488 )
...
Co-authored-by: Donny/강동윤 <kdy1997.dev@gmail.com>
2023-06-07 05:08:35 +00:00
Austaras
62075faeaa
feat(es/minifier): Remove unused labels ( #7478 )
2023-06-07 04:23:40 +00:00
Austaras
0cd2b61b05
feat(es/minifier): Inline for loop variables ( #7445 )
2023-05-25 03:59:02 +00:00
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
Donny/강동윤
246300ae25
feat(es/minifier): Drop expressions using sequential inliner ( #6936 )
2023-04-29 22:19:00 +09:00
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
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/강동윤
6a570a334c
fix(es/ast): Fix EqIgnoreSpan
impl of Number
( #7112 )
...
**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(…)
( #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/강동윤
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
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/강동윤
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/강동윤
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
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/강동윤
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/강동윤
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
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/강동윤
780b5de678
fix(es/minifier): Fix detection of direct eval
( #6215 )
2022-10-21 12:18:10 +09: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