Skip to content

Commit

Permalink
dbg
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Apr 4, 2023
1 parent 4e6a451 commit e3428b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/swc_ecma_minifier/src/compress/optimize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub(super) fn optimizer<'a, M>(
where
M: Mode,
{
dbg!(&*data);
assert!(
options.top_retain.iter().all(|s| s.trim() != ""),
"top_retain should not contain empty string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,7 @@ where
Mergable::Var(a) => {
if self.options.unused {
if let Some(usage) = self.data.vars.get(&left_id.to_id()) {
dbg!(usage);
// We are eliminating one usage, so we use 1 instead of
// 0
if !$force_drop && usage.usage_count == 1 && usage.assign_count == 0
Expand Down
11 changes: 10 additions & 1 deletion crates/swc_ecma_minifier/src/program_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use swc_ecma_usage_analyzer::{
marks::Marks,
};
use swc_ecma_visit::VisitWith;
use tracing::debug;

pub(crate) fn analyze<N>(n: &N, _module_info: &ModuleInfo, marks: Option<Marks>) -> ProgramData
where
Expand Down Expand Up @@ -593,14 +594,18 @@ impl ProgramData {

impl ProgramData {
fn report(&mut self, i: Id, ctx: Ctx, is_modify: bool, dejavu: &mut AHashSet<Id>) {
// trace!("report({}{:?})", i.0, i.1);
debug!("report({}{:?}, is_modify = {:?})", i.0, i.1, is_modify);

let is_first = dejavu.is_empty();

if !dejavu.insert(i.clone()) {
return;
}

dbg!("no dejavu");
dbg!(is_first);
dbg!(self.vars.get(&i));

let inited = self.initialized_vars.contains(&i);

let e = self.vars.entry(i.clone()).or_insert_with(|| {
Expand All @@ -614,6 +619,7 @@ impl ProgramData {
..Default::default()
}
});
dbg!(&*e);

e.inline_prevented |= ctx.inline_prevented;

Expand All @@ -634,6 +640,8 @@ impl ProgramData {
e.executed_multiple_time |= ctx.executed_multiple_time;
e.used_in_cond |= ctx.in_cond;

dbg!(is_modify, ctx.is_exact_reassignment);

if is_modify && ctx.is_exact_reassignment {
if is_first {
e.assign_count += 1;
Expand Down Expand Up @@ -664,6 +672,7 @@ impl ProgramData {
}

e.usage_count += 1;
dbg!(&e.usage_count);
}
}
}

0 comments on commit e3428b2

Please sign in to comment.