Skip to content

Commit 586bfd5

Browse files
authoredDec 5, 2022
refactor(es/minifier): Remove unnecessary code (#6575)
1 parent 2379fc1 commit 586bfd5

File tree

2 files changed

+75
-75
lines changed

2 files changed

+75
-75
lines changed
 

‎crates/swc_ecma_minifier/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub fn optimize(
171171
options.compress.as_ref(),
172172
comments,
173173
marks,
174-
extra.unresolved_mark,
174+
// extra.unresolved_mark,
175175
));
176176
debug_assert_valid(&n);
177177
}

‎crates/swc_ecma_minifier/src/metadata/mod.rs

+74-74
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use swc_common::{
22
comments::{Comment, CommentKind, Comments},
3-
EqIgnoreSpan, Mark, Span, SyntaxContext,
3+
EqIgnoreSpan, Span, SyntaxContext,
44
};
55
use swc_ecma_ast::*;
66
use swc_ecma_utils::find_pat_ids;
@@ -18,13 +18,13 @@ pub(crate) fn info_marker<'a>(
1818
options: Option<&'a CompressOptions>,
1919
comments: Option<&'a dyn Comments>,
2020
marks: Marks,
21-
unresolved_mark: Mark,
21+
// unresolved_mark: Mark,
2222
) -> impl 'a + VisitMut {
2323
InfoMarker {
2424
options,
2525
comments,
2626
marks,
27-
unresolved_mark,
27+
// unresolved_mark,
2828
state: Default::default(),
2929
}
3030
}
@@ -40,7 +40,7 @@ struct InfoMarker<'a> {
4040

4141
comments: Option<&'a dyn Comments>,
4242
marks: Marks,
43-
unresolved_mark: Mark,
43+
// unresolved_mark: Mark,
4444
state: State,
4545
}
4646

@@ -178,12 +178,12 @@ impl VisitMut for InfoMarker<'_> {
178178
)
179179
})
180180
{
181-
if is_standalone(&mut n.function, self.unresolved_mark) {
182-
// self.state.is_bundle = true;
181+
// if is_standalone(&mut n.function, self.unresolved_mark) {
182+
// // self.state.is_bundle = true;
183183

184-
// n.function.span =
185-
// n.function.span.apply_mark(self.marks.standalone);
186-
}
184+
// // n.function.span =
185+
// // n.function.span.apply_mark(self.marks.standalone);
186+
// }
187187
}
188188
}
189189

@@ -267,71 +267,71 @@ impl Visit for TopLevelBindingCollector {
267267
}
268268
}
269269

270-
fn is_standalone<N>(n: &mut N, unresolved_mark: Mark) -> bool
271-
where
272-
N: VisitMutWith<IdentCollector>,
273-
{
274-
let unresolved_ctxt = SyntaxContext::empty().apply_mark(unresolved_mark);
275-
276-
let bindings = {
277-
let mut v = IdentCollector {
278-
ids: Default::default(),
279-
for_binding: true,
280-
is_pat_decl: false,
281-
};
282-
n.visit_mut_with(&mut v);
283-
v.ids
284-
};
285-
286-
let used = {
287-
let mut v = IdentCollector {
288-
ids: Default::default(),
289-
for_binding: false,
290-
is_pat_decl: false,
291-
};
292-
n.visit_mut_with(&mut v);
293-
v.ids
294-
};
295-
296-
for used_id in &used {
297-
if used_id.0.starts_with("__WEBPACK_EXTERNAL_MODULE_") {
298-
continue;
299-
}
300-
301-
match &*used_id.0 {
302-
"__webpack_require__" | "exports" => continue,
303-
_ => {}
304-
}
305-
306-
if used_id.1 == unresolved_ctxt {
307-
// if cfg!(feature = "debug") {
308-
// debug!("bundle: Ignoring {}{:?} (top level)", used_id.0,
309-
// used_id.1); }
310-
continue;
311-
}
312-
313-
if bindings.contains(used_id) {
314-
// if cfg!(feature = "debug") {
315-
// debug!(
316-
// "bundle: Ignoring {}{:?} (local to fn)",
317-
// used_id.0,
318-
// used_id.1
319-
// );
320-
// }
321-
continue;
322-
}
323-
324-
trace_op!(
325-
"bundle: Due to {}{:?}, it's not a bundle",
326-
used_id.0,
327-
used_id.1
328-
);
329-
330-
return false;
331-
}
332-
333-
true
334-
}
270+
// fn is_standalone<N>(n: &mut N, unresolved_mark: Mark) -> bool
271+
// where
272+
// N: VisitMutWith<IdentCollector>,
273+
// {
274+
// let unresolved_ctxt = SyntaxContext::empty().apply_mark(unresolved_mark);
275+
276+
// let bindings = {
277+
// let mut v = IdentCollector {
278+
// ids: Default::default(),
279+
// for_binding: true,
280+
// is_pat_decl: false,
281+
// };
282+
// n.visit_mut_with(&mut v);
283+
// v.ids
284+
// };
285+
286+
// let used = {
287+
// let mut v = IdentCollector {
288+
// ids: Default::default(),
289+
// for_binding: false,
290+
// is_pat_decl: false,
291+
// };
292+
// n.visit_mut_with(&mut v);
293+
// v.ids
294+
// };
295+
296+
// for used_id in &used {
297+
// if used_id.0.starts_with("__WEBPACK_EXTERNAL_MODULE_") {
298+
// continue;
299+
// }
300+
301+
// match &*used_id.0 {
302+
// "__webpack_require__" | "exports" => continue,
303+
// _ => {}
304+
// }
305+
306+
// if used_id.1 == unresolved_ctxt {
307+
// // if cfg!(feature = "debug") {
308+
// // debug!("bundle: Ignoring {}{:?} (top level)", used_id.0,
309+
// // used_id.1); }
310+
// continue;
311+
// }
312+
313+
// if bindings.contains(used_id) {
314+
// // if cfg!(feature = "debug") {
315+
// // debug!(
316+
// // "bundle: Ignoring {}{:?} (local to fn)",
317+
// // used_id.0,
318+
// // used_id.1
319+
// // );
320+
// // }
321+
// continue;
322+
// }
323+
324+
// trace_op!(
325+
// "bundle: Due to {}{:?}, it's not a bundle",
326+
// used_id.0,
327+
// used_id.1
328+
// );
329+
330+
// return false;
331+
// }
332+
333+
// true
334+
// }
335335

336336
struct IdentCollector {
337337
ids: Vec<Id>,

1 commit comments

Comments
 (1)

github-actions[bot] commented on Dec 5, 2022

@github-actions[bot]

Benchmark

Benchmark suite Current: 586bfd5 Previous: a203fdb Ratio
es/full/bugs-1 350100 ns/iter (± 45789) 433858 ns/iter (± 60049) 0.81
es/full/minify/libraries/antd 2079368547 ns/iter (± 56382394) 2421609627 ns/iter (± 69302733) 0.86
es/full/minify/libraries/d3 452273945 ns/iter (± 13399812) 471887492 ns/iter (± 17014566) 0.96
es/full/minify/libraries/echarts 1925032414 ns/iter (± 136213967) 2117942431 ns/iter (± 71712587) 0.91
es/full/minify/libraries/jquery 138793302 ns/iter (± 16550415) 132923529 ns/iter (± 6559938) 1.04
es/full/minify/libraries/lodash 161781225 ns/iter (± 9311455) 152517116 ns/iter (± 5581911) 1.06
es/full/minify/libraries/moment 80058081 ns/iter (± 7019018) 84859642 ns/iter (± 52635634) 0.94
es/full/minify/libraries/react 24731757 ns/iter (± 1327717) 28651895 ns/iter (± 15209523) 0.86
es/full/minify/libraries/terser 380187969 ns/iter (± 23873811) 463019636 ns/iter (± 33428381) 0.82
es/full/minify/libraries/three 668744489 ns/iter (± 29634046) 736593634 ns/iter (± 66658898) 0.91
es/full/minify/libraries/typescript 4079520728 ns/iter (± 135939358) 4838105034 ns/iter (± 148445746) 0.84
es/full/minify/libraries/victory 971799374 ns/iter (± 85780814) 1112553848 ns/iter (± 83094318) 0.87
es/full/minify/libraries/vue 204497167 ns/iter (± 13635709) 215182264 ns/iter (± 24983236) 0.95
es/full/codegen/es3 35216 ns/iter (± 4610) 41999 ns/iter (± 886) 0.84
es/full/codegen/es5 34559 ns/iter (± 3108) 41891 ns/iter (± 2310) 0.82
es/full/codegen/es2015 34962 ns/iter (± 9023) 41479 ns/iter (± 2752) 0.84
es/full/codegen/es2016 35475 ns/iter (± 1608) 41953 ns/iter (± 5247) 0.85
es/full/codegen/es2017 35138 ns/iter (± 1558) 41691 ns/iter (± 3435) 0.84
es/full/codegen/es2018 34240 ns/iter (± 788) 43614 ns/iter (± 25098) 0.79
es/full/codegen/es2019 34225 ns/iter (± 1433) 41370 ns/iter (± 4333) 0.83
es/full/codegen/es2020 34298 ns/iter (± 1822) 42106 ns/iter (± 6950) 0.81
es/full/all/es3 191446317 ns/iter (± 25438241) 237538178 ns/iter (± 28711261) 0.81
es/full/all/es5 183373108 ns/iter (± 9189378) 225625443 ns/iter (± 17751187) 0.81
es/full/all/es2015 165586574 ns/iter (± 25538818) 179765309 ns/iter (± 17404803) 0.92
es/full/all/es2016 162010049 ns/iter (± 20415451) 182401069 ns/iter (± 15335932) 0.89
es/full/all/es2017 147239744 ns/iter (± 11160821) 177936455 ns/iter (± 15811367) 0.83
es/full/all/es2018 156883716 ns/iter (± 14331707) 175847881 ns/iter (± 19239088) 0.89
es/full/all/es2019 143742018 ns/iter (± 9816889) 175094541 ns/iter (± 17610050) 0.82
es/full/all/es2020 143493057 ns/iter (± 14207730) 168017276 ns/iter (± 15066806) 0.85
es/full/parser 719063 ns/iter (± 78550) 873718 ns/iter (± 35587) 0.82
es/full/base/fixer 26510 ns/iter (± 1024) 32642 ns/iter (± 1935) 0.81
es/full/base/resolver_and_hygiene 93078 ns/iter (± 6110) 117221 ns/iter (± 3824) 0.79
serialization of ast node 211 ns/iter (± 5) 252 ns/iter (± 13) 0.84
serialization of serde 234 ns/iter (± 7) 266 ns/iter (± 20) 0.88

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.