mirror of
https://github.com/swc-project/swc.git
synced 2024-12-26 07:02:28 +03:00
refactor(es/minifier): Support stable rustc (#7734)
This commit is contained in:
parent
14906e279f
commit
f7afe7edec
@ -635,7 +635,7 @@ impl Optimizer<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
trace_op!("iife: Empry function");
|
||||
trace_op!("iife: Empty function");
|
||||
|
||||
let body = f.function.body.as_mut().unwrap();
|
||||
if body.stmts.is_empty() && call.args.is_empty() {
|
||||
@ -724,7 +724,7 @@ impl Optimizer<'_> {
|
||||
// Abort on eval.
|
||||
// See https://github.com/swc-project/swc/pull/6478
|
||||
//
|
||||
// We completetly abort on eval, because we cannot know whether a variable in
|
||||
// We completely abort on eval, because we cannot know whether a variable in
|
||||
// upper scope will be afftected by eval.
|
||||
// https://github.com/swc-project/swc/issues/6628
|
||||
if self.data.top.has_eval_call {
|
||||
@ -1077,11 +1077,14 @@ impl Optimizer<'_> {
|
||||
|
||||
Expr::Arrow(ArrowExpr {
|
||||
params,
|
||||
body: box BlockStmtOrExpr::Expr(body),
|
||||
body,
|
||||
is_async: false,
|
||||
is_generator: false,
|
||||
..
|
||||
}) => params.iter().all(|p| p.is_ident()) && self.can_be_inlined_for_iife(body),
|
||||
}) if body.is_expr() => {
|
||||
params.iter().all(|p| p.is_ident())
|
||||
&& self.can_be_inlined_for_iife(body.as_expr().unwrap())
|
||||
}
|
||||
|
||||
_ => false,
|
||||
}
|
||||
|
@ -131,13 +131,8 @@ impl Pure<'_> {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Expr::Arrow(
|
||||
m @ ArrowExpr {
|
||||
body: box BlockStmtOrExpr::BlockStmt(..),
|
||||
..
|
||||
},
|
||||
) = &mut *kv.value
|
||||
{
|
||||
match &mut *kv.value {
|
||||
Expr::Arrow(m) if m.body.is_block_stmt() => {
|
||||
*p = Prop::Method(MethodProp {
|
||||
key: kv.key.take(),
|
||||
function: Box::new(Function {
|
||||
@ -161,6 +156,8 @@ impl Pure<'_> {
|
||||
}),
|
||||
});
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,6 @@
|
||||
#![allow(clippy::only_used_in_recursion)]
|
||||
#![allow(unstable_name_collisions)]
|
||||
#![allow(clippy::match_like_matches_macro)]
|
||||
#![feature(box_patterns)]
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use swc_common::{comments::Comments, pass::Repeated, sync::Lrc, SourceMap, SyntaxContext};
|
||||
|
@ -101,7 +101,24 @@ fn should_replace(pred: &Expr, node: &Expr) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
match (pred, node) {
|
||||
fn match_node(node: &Expr) -> Option<(&Expr, &MemberProp)> {
|
||||
match node {
|
||||
Expr::Member(MemberExpr {
|
||||
obj: node_obj,
|
||||
prop: nodes,
|
||||
..
|
||||
}) => Some((node_obj, nodes)),
|
||||
|
||||
Expr::OptChain(OptChainExpr { base, .. }) => {
|
||||
let base = base.as_member()?;
|
||||
Some((&base.obj, &base.prop))
|
||||
}
|
||||
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
match (pred, match_node(node)) {
|
||||
// super?. is invalid
|
||||
(
|
||||
Expr::Member(MemberExpr {
|
||||
@ -109,20 +126,7 @@ fn should_replace(pred: &Expr, node: &Expr) -> bool {
|
||||
prop: pred,
|
||||
..
|
||||
}),
|
||||
Expr::Member(MemberExpr {
|
||||
obj: node_obj,
|
||||
prop: nodes,
|
||||
..
|
||||
})
|
||||
| Expr::OptChain(OptChainExpr {
|
||||
base:
|
||||
box OptChainBase::Member(MemberExpr {
|
||||
obj: node_obj,
|
||||
prop: nodes,
|
||||
..
|
||||
}),
|
||||
..
|
||||
}),
|
||||
Some((node_obj, nodes)),
|
||||
) if !(pred.is_computed() || nodes.is_computed()) => {
|
||||
if !pred.eq_ignore_span(nodes) {
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user