Skip to content

Commit

Permalink
fix(es/minifier): Abort property hoister on this usage (#8647)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #8643
  • Loading branch information
kdy1 authored Feb 19, 2024
1 parent d7434be commit 9715320
Show file tree
Hide file tree
Showing 5 changed files with 554 additions and 10 deletions.
6 changes: 4 additions & 2 deletions crates/swc_ecma_minifier/src/compress/optimize/props.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use swc_common::{util::take::Take, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_utils::{private_ident, prop_name_eq, ExprExt};
use swc_ecma_utils::{contains_this_expr, private_ident, prop_name_eq, ExprExt};

use super::{unused::PropertyAccessOpts, Optimizer};
use crate::util::deeply_contains_this_expr;
Expand Down Expand Up @@ -222,7 +222,9 @@ impl Optimizer<'_> {

fn is_expr_fine_for_hoist_props(value: &Expr) -> bool {
match value {
Expr::Ident(..) | Expr::Lit(..) | Expr::Arrow(..) | Expr::Fn(..) | Expr::Class(..) => true,
Expr::Ident(..) | Expr::Lit(..) | Expr::Arrow(..) | Expr::Class(..) => true,

Expr::Fn(f) => !contains_this_expr(&f.function.body),

Expr::Unary(u) => match u.op {
op!("void") | op!("typeof") | op!("!") => is_expr_fine_for_hoist_props(&u.arg),
Expand Down
Loading

0 comments on commit 9715320

Please sign in to comment.