Skip to content

Commit

Permalink
fix(es): Mark TypeScript nodes as reachable from Evaluator (#9440)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Aug 16, 2024
1 parent f50a974 commit 308e5ec
Show file tree
Hide file tree
Showing 34 changed files with 56 additions and 48 deletions.
8 changes: 8 additions & 0 deletions .changeset/cyan-tigers-sing.md
Original file line number Diff line number Diff line change
@@ -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`
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/compress/hoist_decls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/compress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/compress/optimize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/compress/optimize/switches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/compress/optimize/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions crates/swc_ecma_minifier/src/compress/optimize/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/compress/pure/dead_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/compress/pure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
{
Expand Down
6 changes: 3 additions & 3 deletions crates/swc_ecma_minifier/src/compress/pure/vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down Expand Up @@ -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) {}
Expand Down Expand Up @@ -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) {}
Expand Down
6 changes: 3 additions & 3 deletions crates/swc_ecma_minifier/src/compress/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {}

Expand Down Expand Up @@ -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) {}
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/compress/util/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_minifier/src/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/pass/global_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/pass/hygiene/vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/pass/mangle_names/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/pass/mangle_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/pass/merge_exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/pass/postcompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/pass/precompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/src/util/base54.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ struct CharFreqAnalyzer<'a> {
}

impl Visit for CharFreqAnalyzer<'_> {
noop_visit_type!(fail);
noop_visit_type!();

visit_obj_and_computed!();

Expand Down
10 changes: 5 additions & 5 deletions crates/swc_ecma_minifier/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -331,7 +331,7 @@ pub(crate) struct IdentUsageCollector {
}

impl Visit for IdentUsageCollector {
noop_visit_type!(fail);
noop_visit_type!();

visit_obj_and_computed!();

Expand Down Expand Up @@ -393,7 +393,7 @@ pub(crate) struct CapturedIdCollector {
}

impl Visit for CapturedIdCollector {
noop_visit_type!(fail);
noop_visit_type!();

visit_obj_and_computed!();

Expand Down Expand Up @@ -497,7 +497,7 @@ pub(crate) struct EvalFinder {
}

impl Visit for EvalFinder {
noop_visit_type!(fail);
noop_visit_type!();

visit_obj_and_computed!();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 308e5ec

Please sign in to comment.