File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
crates/swc_ecma_minifier/src/compress/optimize Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ swc_ecma_minifier : minor
3
+ swc_core : minor
4
+ ---
5
+
6
+ perf(es/minifier): Do heavy operation only if required
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ impl Optimizer<'_> {
89
89
let is_inline_enabled =
90
90
self . options . reduce_vars || self . options . collapse_vars || self . options . inline != 0 ;
91
91
92
- self . vars . inline_with_multi_replacer ( init ) ;
92
+ let mut inlined_into_init = false ;
93
93
94
94
let id = ident. to_id ( ) ;
95
95
@@ -107,6 +107,9 @@ impl Optimizer<'_> {
107
107
&& !usage. used_as_ref
108
108
{
109
109
if let Expr :: Array ( arr) = init {
110
+ self . vars . inline_with_multi_replacer ( arr) ;
111
+ inlined_into_init = true ;
112
+
110
113
if arr. elems . len ( ) < 32
111
114
&& arr. elems . iter ( ) . all ( |e| match e {
112
115
Some ( ExprOrSpread { spread : None , expr } ) => match & * * expr {
@@ -257,6 +260,11 @@ impl Optimizer<'_> {
257
260
_ => false ,
258
261
}
259
262
{
263
+ if !inlined_into_init {
264
+ inlined_into_init = true ;
265
+ self . vars . inline_with_multi_replacer ( init) ;
266
+ }
267
+
260
268
self . mode . store ( id. clone ( ) , & * init) ;
261
269
262
270
let VarUsageInfo {
@@ -498,6 +506,10 @@ impl Optimizer<'_> {
498
506
return ;
499
507
}
500
508
509
+ if !inlined_into_init {
510
+ self . vars . inline_with_multi_replacer ( init) ;
511
+ }
512
+
501
513
report_change ! (
502
514
"inline: Decided to inline var '{}' because it's used only once" ,
503
515
ident
You can’t perform that action at this time.
0 commit comments