mirror of
https://github.com/swc-project/swc.git
synced 2024-10-05 04:39:06 +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();
|
let body = f.function.body.as_mut().unwrap();
|
||||||
if body.stmts.is_empty() && call.args.is_empty() {
|
if body.stmts.is_empty() && call.args.is_empty() {
|
||||||
@ -724,7 +724,7 @@ impl Optimizer<'_> {
|
|||||||
// Abort on eval.
|
// Abort on eval.
|
||||||
// See https://github.com/swc-project/swc/pull/6478
|
// 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.
|
// upper scope will be afftected by eval.
|
||||||
// https://github.com/swc-project/swc/issues/6628
|
// https://github.com/swc-project/swc/issues/6628
|
||||||
if self.data.top.has_eval_call {
|
if self.data.top.has_eval_call {
|
||||||
@ -1077,11 +1077,14 @@ impl Optimizer<'_> {
|
|||||||
|
|
||||||
Expr::Arrow(ArrowExpr {
|
Expr::Arrow(ArrowExpr {
|
||||||
params,
|
params,
|
||||||
body: box BlockStmtOrExpr::Expr(body),
|
body,
|
||||||
is_async: false,
|
is_async: false,
|
||||||
is_generator: 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,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
@ -131,35 +131,32 @@ impl Pure<'_> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Expr::Arrow(
|
match &mut *kv.value {
|
||||||
m @ ArrowExpr {
|
Expr::Arrow(m) if m.body.is_block_stmt() => {
|
||||||
body: box BlockStmtOrExpr::BlockStmt(..),
|
*p = Prop::Method(MethodProp {
|
||||||
..
|
key: kv.key.take(),
|
||||||
},
|
function: Box::new(Function {
|
||||||
) = &mut *kv.value
|
params: m
|
||||||
{
|
.params
|
||||||
*p = Prop::Method(MethodProp {
|
.take()
|
||||||
key: kv.key.take(),
|
.into_iter()
|
||||||
function: Box::new(Function {
|
.map(|pat| Param {
|
||||||
params: m
|
span: DUMMY_SP,
|
||||||
.params
|
decorators: Default::default(),
|
||||||
.take()
|
pat,
|
||||||
.into_iter()
|
})
|
||||||
.map(|pat| Param {
|
.collect(),
|
||||||
span: DUMMY_SP,
|
decorators: Default::default(),
|
||||||
decorators: Default::default(),
|
span: m.span,
|
||||||
pat,
|
body: m.body.take().block_stmt(),
|
||||||
})
|
is_generator: m.is_generator,
|
||||||
.collect(),
|
is_async: m.is_async,
|
||||||
decorators: Default::default(),
|
type_params: Default::default(),
|
||||||
span: m.span,
|
return_type: Default::default(),
|
||||||
body: m.body.take().block_stmt(),
|
}),
|
||||||
is_generator: m.is_generator,
|
});
|
||||||
is_async: m.is_async,
|
}
|
||||||
type_params: Default::default(),
|
_ => (),
|
||||||
return_type: Default::default(),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
#![allow(clippy::only_used_in_recursion)]
|
#![allow(clippy::only_used_in_recursion)]
|
||||||
#![allow(unstable_name_collisions)]
|
#![allow(unstable_name_collisions)]
|
||||||
#![allow(clippy::match_like_matches_macro)]
|
#![allow(clippy::match_like_matches_macro)]
|
||||||
#![feature(box_patterns)]
|
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use swc_common::{comments::Comments, pass::Repeated, sync::Lrc, SourceMap, SyntaxContext};
|
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;
|
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
|
// super?. is invalid
|
||||||
(
|
(
|
||||||
Expr::Member(MemberExpr {
|
Expr::Member(MemberExpr {
|
||||||
@ -109,20 +126,7 @@ fn should_replace(pred: &Expr, node: &Expr) -> bool {
|
|||||||
prop: pred,
|
prop: pred,
|
||||||
..
|
..
|
||||||
}),
|
}),
|
||||||
Expr::Member(MemberExpr {
|
Some((node_obj, nodes)),
|
||||||
obj: node_obj,
|
|
||||||
prop: nodes,
|
|
||||||
..
|
|
||||||
})
|
|
||||||
| Expr::OptChain(OptChainExpr {
|
|
||||||
base:
|
|
||||||
box OptChainBase::Member(MemberExpr {
|
|
||||||
obj: node_obj,
|
|
||||||
prop: nodes,
|
|
||||||
..
|
|
||||||
}),
|
|
||||||
..
|
|
||||||
}),
|
|
||||||
) if !(pred.is_computed() || nodes.is_computed()) => {
|
) if !(pred.is_computed() || nodes.is_computed()) => {
|
||||||
if !pred.eq_ignore_span(nodes) {
|
if !pred.eq_ignore_span(nodes) {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user