Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Apr 4, 2023
1 parent 18a699c commit 9610499
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions crates/swc_ecma_usage_analyzer/src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,19 +1205,44 @@ where
..self.ctx
};

if let Some(..) = &self.marks {
if let Some(marks) = &self.marks {
if let VarDeclarator {
name: Pat::Ident(id),
init: Some(..),
init: Some(init),
definite: false,
..
} = e
{
// TODO: merge with may_have_side_effects

let id = id.to_id();
self.used_recursively
.insert(id.clone(), RecursiveUsage::Var { can_ignore: false });
e.init.visit_with(&mut *self.with_ctx(ctx));
self.used_recursively.remove(&id);

match init {
Expr::Call(call) => {
let can_ignore = call.span.has_mark(marks.pure);

self.used_recursively
.insert(id.clone(), RecursiveUsage::Var { can_ignore });

call.callee.visit_with(&mut *self.with_ctx(ctx));

self.used_recursively.remove(&id);

self.used_recursively
.insert(id.clone(), RecursiveUsage::Var { can_ignore: false });
call.args.visit_with(&mut *self.with_ctx(ctx));
self.used_recursively.remove(&id);
}
_ => {
self.used_recursively
.insert(id.clone(), RecursiveUsage::Var { can_ignore: false });

e.init.visit_with(&mut *self.with_ctx(ctx));

self.used_recursively.remove(&id);
}
}

return;
}
}
Expand Down

0 comments on commit 9610499

Please sign in to comment.