Skip to content

Commit

Permalink
used_with_in
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Aug 28, 2024
1 parent dbb02fe commit 2cd04fc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/swc_ecma_minifier/src/compress/optimize/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl Optimizer<'_> {
|| usage.used_as_arg
|| usage.indexed_with_dynamic_key
|| usage.used_recursively
|| usage.used_with_in
{
log_abort!("hoist_props: Variable `{}` is not a candidate", name.id);
return None;
Expand Down
9 changes: 9 additions & 0 deletions crates/swc_ecma_minifier/src/program_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ pub(crate) struct VarUsageInfo {
pub(crate) accessed_props: Box<AHashMap<JsWord, u32>>,

pub(crate) used_recursively: bool,

pub(crate) used_with_in: bool,
}

impl Default for VarUsageInfo {
Expand Down Expand Up @@ -162,6 +164,7 @@ impl Default for VarUsageInfo {
is_top_level: Default::default(),
assigned_fn_local: true,
used_as_ref: false,
used_with_in: false,
}
}
}
Expand Down Expand Up @@ -292,6 +295,8 @@ impl Storage for ProgramData {

e.get_mut().assigned_fn_local &= var_info.assigned_fn_local;

e.get_mut().used_with_in |= var_info.used_with_in;

for (k, v) in *var_info.accessed_props {
*e.get_mut().accessed_props.entry(k).or_default() += v;
}
Expand Down Expand Up @@ -571,6 +576,10 @@ impl VarDataLike for VarUsageInfo {
fn mark_used_recursively(&mut self) {
self.used_recursively = true;
}

fn mark_used_with_in(&mut self) {
self.used_with_in = true;
}
}

impl ProgramData {
Expand Down
1 change: 1 addition & 0 deletions crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ where
if e.op == op!("in") {
for_each_id_ref_in_expr(&e.right, &mut |obj| {
let var = self.data.var_or_default(obj.to_id());
var.mark_used_with_in();

match &*e.left {
Expr::Lit(Lit::Str(prop)) if prop.value.parse::<f64>().is_err() => {
Expand Down
2 changes: 2 additions & 0 deletions crates/swc_ecma_usage_analyzer/src/analyzer/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,6 @@ pub trait VarDataLike: Sized {
fn mark_used_above_decl(&mut self);

fn mark_used_recursively(&mut self);

fn mark_used_with_in(&mut self);
}

0 comments on commit 2cd04fc

Please sign in to comment.