fix(es): Mark TypeScript nodes as reachable from Evaluator (#9440)

This commit is contained in:
Donny/강동윤 2024-08-16 21:49:11 +09:00 committed by GitHub
parent f50a974fb1
commit 308e5ec81b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
34 changed files with 56 additions and 48 deletions

View File

@ -0,0 +1,8 @@
---
swc_core: patch
swc_ecma_usage_analyzer: patch
swc_ecma_minifier: patch
swc_ecma_transforms_optimization: patch
---
fix(es): Mark TypeScript nodes as reachable from `Evaluator`

View File

@ -279,7 +279,7 @@ impl Hoister<'_> {
}
impl VisitMut for Hoister<'_> {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_module_items(&mut self, stmts: &mut Vec<ModuleItem>) {
self.handle_stmt_likes(stmts);

View File

@ -324,7 +324,7 @@ impl Compressor<'_> {
}
impl VisitMut for Compressor<'_> {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_script(&mut self, n: &mut Script) {
self.optimize_unit_repeatedly(n);

View File

@ -146,7 +146,7 @@ impl ArgReplacer<'_> {
}
impl VisitMut for ArgReplacer<'_> {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
/// Noop.
fn visit_mut_arrow_expr(&mut self, _: &mut ArrowExpr) {}

View File

@ -529,7 +529,7 @@ pub(super) struct ReturnFinder {
}
impl Visit for ReturnFinder {
noop_visit_type!(fail);
noop_visit_type!();
fn visit_return_stmt(&mut self, n: &ReturnStmt) {
n.visit_children_with(self);

View File

@ -1497,7 +1497,7 @@ impl Optimizer<'_> {
}
impl VisitMut for Optimizer<'_> {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
#[cfg_attr(feature = "debug", tracing::instrument(skip_all))]
fn visit_mut_arrow_expr(&mut self, n: &mut ArrowExpr) {

View File

@ -2599,7 +2599,7 @@ struct UsageCounter<'a> {
}
impl Visit for UsageCounter<'_> {
noop_visit_type!(fail);
noop_visit_type!();
fn visit_ident(&mut self, i: &Ident) {
if self.target.sym == i.sym && self.target.ctxt == i.ctxt {

View File

@ -560,7 +560,7 @@ struct BreakFinder {
}
impl Visit for BreakFinder {
noop_visit_type!(fail);
noop_visit_type!();
fn visit_break_stmt(&mut self, s: &BreakStmt) {
if !self.top_level && s.label.is_none() {

View File

@ -974,7 +974,7 @@ struct ThisPropertyVisitor {
}
impl Visit for ThisPropertyVisitor {
noop_visit_type!(fail);
noop_visit_type!();
fn visit_assign_expr(&mut self, e: &AssignExpr) {
if self.should_abort {

View File

@ -307,7 +307,7 @@ enum FinalizerMode {
}
impl VisitMut for Finalizer<'_> {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_callee(&mut self, e: &mut Callee) {
e.visit_mut_children_with(self);
@ -483,7 +483,7 @@ impl<'a> NormalMultiReplacer<'a> {
}
impl VisitMut for NormalMultiReplacer<'_> {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_expr(&mut self, e: &mut Expr) {
if self.vars.is_empty() {
@ -576,7 +576,7 @@ impl ExprReplacer {
}
impl VisitMut for ExprReplacer {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_expr(&mut self, e: &mut Expr) {
e.visit_mut_children_with(self);

View File

@ -610,7 +610,7 @@ struct LabelFinder<'a> {
found: bool,
}
impl Visit for LabelFinder<'_> {
noop_visit_type!(fail);
noop_visit_type!();
fn visit_break_stmt(&mut self, s: &BreakStmt) {
match &s.label {

View File

@ -247,7 +247,7 @@ impl Pure<'_> {
}
impl VisitMut for Pure<'_> {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_assign_expr(&mut self, e: &mut AssignExpr) {
{

View File

@ -300,7 +300,7 @@ pub(super) struct VarWithOutInitCounter {
}
impl Visit for VarWithOutInitCounter {
noop_visit_type!(fail);
noop_visit_type!();
fn visit_arrow_expr(&mut self, _: &ArrowExpr) {}
@ -368,7 +368,7 @@ pub(super) struct VarMover {
}
impl VisitMut for VarMover {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
/// Noop
fn visit_mut_arrow_expr(&mut self, _: &mut ArrowExpr) {}
@ -486,7 +486,7 @@ pub(super) struct VarPrepender {
}
impl VisitMut for VarPrepender {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
/// Noop
fn visit_mut_arrow_expr(&mut self, _: &mut ArrowExpr) {}

View File

@ -568,7 +568,7 @@ impl<F> VisitMut for ExprReplacer<F>
where
F: FnMut(&mut Expr),
{
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_expr(&mut self, e: &mut Expr) {
e.visit_mut_children_with(self);
@ -687,7 +687,7 @@ impl UnreachableHandler {
}
impl VisitMut for UnreachableHandler {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_arrow_expr(&mut self, _: &mut ArrowExpr) {}
@ -737,7 +737,7 @@ pub struct SuperFinder {
}
impl Visit for SuperFinder {
noop_visit_type!(fail);
noop_visit_type!();
/// Don't recurse into constructor
fn visit_constructor(&mut self, _: &Constructor) {}

View File

@ -11,7 +11,7 @@ use crate::{compress::util::negate, debug::dump};
struct UnwrapParen;
impl VisitMut for UnwrapParen {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_expr(&mut self, e: &mut Expr) {
e.visit_mut_children_with(self);

View File

@ -15,7 +15,7 @@ use tracing::debug;
pub(crate) struct Debugger {}
impl VisitMut for Debugger {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_ident(&mut self, n: &mut Ident) {
if !cfg!(feature = "debug") {

View File

@ -91,7 +91,7 @@ impl InfoMarker<'_> {
}
impl VisitMut for InfoMarker<'_> {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_call_expr(&mut self, n: &mut CallExpr) {
n.visit_mut_children_with(self);
@ -234,7 +234,7 @@ struct InfoCollector<'a> {
}
impl Visit for InfoCollector<'_> {
noop_visit_type!(fail);
noop_visit_type!();
fn visit_export_decl(&mut self, f: &ExportDecl) {
f.visit_children_with(self);

View File

@ -35,7 +35,7 @@ impl CompilerPass for GlobalDefs {
/// We use [VisitMut] instead of [swc_ecma_visit::Fold] because it's faster.
impl VisitMut for GlobalDefs {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_assign_expr(&mut self, n: &mut AssignExpr) {
let old = self.in_lhs_of_assign;

View File

@ -83,7 +83,7 @@ macro_rules! scoped {
}
impl Visit for VarAnalyzer<'_> {
noop_visit_type!(fail);
noop_visit_type!();
fn visit_arrow_expr(&mut self, n: &ArrowExpr) {
scoped!(self, n);

View File

@ -77,7 +77,7 @@ impl LabelMangler {
}
impl VisitMut for LabelMangler {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_labeled_stmt(&mut self, s: &mut LabeledStmt) {
self.mangle(&mut s.label);

View File

@ -35,7 +35,7 @@ impl Preserver {
}
impl Visit for Preserver {
noop_visit_type!(fail);
noop_visit_type!();
fn visit_block_stmt(&mut self, n: &BlockStmt) {
let old_top_level = self.in_top_level;

View File

@ -43,7 +43,7 @@ impl PrivateNameMangler {
}
impl VisitMut for PrivateNameMangler {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_member_expr(&mut self, n: &mut MemberExpr) {
n.obj.visit_mut_with(self);

View File

@ -238,7 +238,7 @@ impl Mangler<'_> {
}
impl VisitMut for Mangler<'_> {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_call_expr(&mut self, call: &mut CallExpr) {
call.visit_mut_children_with(self);

View File

@ -16,7 +16,7 @@ struct Merger {
}
impl VisitMut for Merger {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_module_items(&mut self, stmts: &mut Vec<ModuleItem>) {
let was_module = maybe_par!(

View File

@ -36,7 +36,7 @@ impl Parallel for PostcompressOptimizer<'_> {
}
impl VisitMut for PostcompressOptimizer<'_> {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_export_decl(&mut self, export: &mut ExportDecl) {
match &mut export.decl {

View File

@ -27,7 +27,7 @@ impl Parallel for PrecompressOptimizer {
}
impl VisitMut for PrecompressOptimizer {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_stmts(&mut self, n: &mut Vec<Stmt>) {
self.maybe_par(*HEAVY_TASK_PARALLELS, n, |v, n| {

View File

@ -296,7 +296,7 @@ struct CharFreqAnalyzer<'a> {
}
impl Visit for CharFreqAnalyzer<'_> {
noop_visit_type!(fail);
noop_visit_type!();
visit_obj_and_computed!();

View File

@ -216,7 +216,7 @@ pub(crate) struct LeapFinder {
}
impl Visit for LeapFinder {
noop_visit_type!(fail);
noop_visit_type!();
fn visit_await_expr(&mut self, n: &AwaitExpr) {
n.visit_children_with(self);
@ -308,7 +308,7 @@ pub struct DeepThisExprVisitor {
}
impl Visit for DeepThisExprVisitor {
noop_visit_type!(fail);
noop_visit_type!();
fn visit_this_expr(&mut self, _: &ThisExpr) {
self.found = true;
@ -331,7 +331,7 @@ pub(crate) struct IdentUsageCollector {
}
impl Visit for IdentUsageCollector {
noop_visit_type!(fail);
noop_visit_type!();
visit_obj_and_computed!();
@ -393,7 +393,7 @@ pub(crate) struct CapturedIdCollector {
}
impl Visit for CapturedIdCollector {
noop_visit_type!(fail);
noop_visit_type!();
visit_obj_and_computed!();
@ -497,7 +497,7 @@ pub(crate) struct EvalFinder {
}
impl Visit for EvalFinder {
noop_visit_type!(fail);
noop_visit_type!();
visit_obj_and_computed!();

View File

@ -72,7 +72,7 @@ impl Parallel for Remover {
}
impl VisitMut for Remover {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_expr(&mut self, e: &mut Expr) {
e.visit_mut_children_with(self);
@ -1896,7 +1896,7 @@ fn check_for_stopper(s: &[Stmt], only_conditional: bool) -> bool {
}
impl Visit for Visitor {
noop_visit_type!(fail);
noop_visit_type!();
fn visit_switch_case(&mut self, node: &SwitchCase) {
let old = self.in_cond;

View File

@ -355,7 +355,7 @@ impl Analyzer<'_> {
}
impl Visit for Analyzer<'_> {
noop_visit_type!(fail);
noop_visit_type!();
fn visit_callee(&mut self, n: &Callee) {
n.visit_children_with(self);
@ -658,7 +658,7 @@ impl TreeShaker {
}
impl VisitMut for TreeShaker {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_assign_expr(&mut self, n: &mut AssignExpr) {
n.visit_mut_children_with(self);

View File

@ -1213,7 +1213,7 @@ impl SimplifyExpr {
}
impl VisitMut for SimplifyExpr {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_assign_expr(&mut self, n: &mut AssignExpr) {
let old = self.is_modifying;

View File

@ -103,7 +103,7 @@ impl Inlining<'_> {
}
impl VisitMut for Inlining<'_> {
noop_visit_mut_type!(fail);
noop_visit_mut_type!();
fn visit_mut_arrow_expr(&mut self, node: &mut ArrowExpr) {
self.visit_with_child(ScopeKind::Fn { named: false }, node)
@ -739,7 +739,7 @@ struct IdentListVisitor<'a, 'b> {
}
impl Visit for IdentListVisitor<'_, '_> {
noop_visit_type!(fail);
noop_visit_type!();
visit_obj_and_computed!();
@ -754,7 +754,7 @@ struct WriteVisitor<'a, 'b> {
}
impl Visit for WriteVisitor<'_, '_> {
noop_visit_type!(fail);
noop_visit_type!();
visit_obj_and_computed!();

View File

@ -120,7 +120,7 @@ impl InfectionCollector<'_> {
}
impl Visit for InfectionCollector<'_> {
noop_visit_type!(fail);
noop_visit_type!();
fn visit_bin_expr(&mut self, e: &BinExpr) {
match e.op {

View File

@ -215,7 +215,7 @@ impl<S> Visit for UsageAnalyzer<S>
where
S: Storage,
{
noop_visit_type!(fail);
noop_visit_type!();
fn visit_array_lit(&mut self, n: &ArrayLit) {
let ctx = Ctx {