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/강동윤
0aab90c005
fix(es/minifier): Fix a inliner bug related to Script
( #7288 )
...
**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 ( #7246 )
...
**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 ( #7245 )
...
**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 ( #7200 )
...
**Related issue:**
- Closes https://github.com/swc-project/swc/issues/7194 .
2023-04-05 04:35:37 +00:00
magic-akari
3ca954b9f9
fix(es/helpers): Use snake_case for helpers ( #7147 )
...
**Related issue:**
- Closes https://github.com/swc-project/swc/issues/7144 .
- Closes https://github.com/swc-project/swc/issues/7118 .
2023-03-31 15:15:21 +09:00
Donny/강동윤
0259a7465f
build(cargo): Update rustc
to nightly-2023-03-20
( #7170 )
...
**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 ( #7162 )
...
**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
( #7154 )
...
**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 ( #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
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
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/강동윤
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
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/강동윤
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
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/강동윤
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/강동윤
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
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/강동윤
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/강동윤
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/강동윤
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/강동윤
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/강동윤
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/강동윤
66196a65be
feat(es/minifier): Inline pure array literal partially ( #6099 )
2022-10-12 02:29:40 +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
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/강동윤
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
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/강동윤
2ee3ad0066
fix(es/minifier): Don't inline into nested scope ( #6002 )
...
**Related issue:**
- https://github.com/vercel/next.js/discussions/30237#discussioncomment-3768734
2022-09-30 08:53:20 +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/강동윤
8c4873f81e
test(es/minifier): Remove mangle-only snapshots ( #5979 )
...
**Description:**
We don't have to store snapshots of all fixtures.
2022-09-28 21:35:52 +09:00
Austaras
aff4ea5f44
fix(es/minifier): Preserve exports in DCE ( #5973 )
2022-09-28 05:35:51 +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
Austaras
573418fc96
fix(es/resolver): Use a separate mark for the name of FnExpr
( #5959 )
2022-09-27 14:50:35 +09:00
Donny/강동윤
33a15c8d82
fix(es/minifier): Fix analysis of parameters ( #5954 )
...
**Description:**
Although the author of the issue talked about `@react-pdf/renderer`, it's a bug related to `brotli`, not react pdf renderer.
After investigation, I found that the bug is caused by not marking parameters as initialized. So I fixed the analyzer.
**Related issue:**
- https://github.com/vercel/next.js/issues/40803 .
2022-09-27 12:19:36 +09:00
Donny/강동윤
9d1974248d
fix(es/minifier): Fix skipping logic of sequential inliner ( #5956 )
...
**Description:**
This PR implements `is_skippable_for_seq` fully.
**Related issue:**
- Closes https://github.com/swc-project/swc/issues/5935 .
2022-09-26 15:05:52 +00:00