mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 13:51:19 +03:00
feat(es/minifier): Improve drop_console
(#2830)
swc_ecma_minifier: - Implement more rules for `drop_console`. (Closes #2807)
This commit is contained in:
parent
bfa6458737
commit
c5768d7672
@ -46,18 +46,30 @@ impl VisitMut for DropConsole {
|
||||
computed: false,
|
||||
..
|
||||
}) => {
|
||||
match (&**callee_obj, &**callee_prop) {
|
||||
(Expr::Ident(obj), Expr::Ident(prop)) => {
|
||||
if obj.sym != *"console" {
|
||||
return;
|
||||
let mut loop_co = &**callee_obj;
|
||||
let mut loop_cp = &**callee_prop;
|
||||
loop {
|
||||
match (loop_co, loop_cp) {
|
||||
(Expr::Ident(obj), Expr::Ident(_prop)) => {
|
||||
if obj.sym != *"console" {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
match &*prop.sym {
|
||||
"log" | "info" => {}
|
||||
_ => return,
|
||||
(
|
||||
Expr::Member(MemberExpr {
|
||||
obj: ExprOrSuper::Expr(loop_co_obj),
|
||||
prop: loop_cp_prop,
|
||||
computed: false,
|
||||
..
|
||||
}),
|
||||
Expr::Ident(_prop),
|
||||
) => {
|
||||
loop_co = &loop_co_obj;
|
||||
loop_cp = &loop_cp_prop;
|
||||
}
|
||||
_ => return,
|
||||
}
|
||||
_ => return,
|
||||
}
|
||||
|
||||
// Sioplifier will remove side-effect-free items.
|
||||
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"unused": true,
|
||||
"drop_console": true
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
export default function A() {
|
||||
console.log(123);
|
||||
console.log.apply(console, arguments);
|
||||
console.a.b.c(console, arguments);
|
||||
console.any();
|
||||
console.warn();
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
export default function A() {
|
||||
};
|
Loading…
Reference in New Issue
Block a user