Skip to content

Commit

Permalink
Grow stack when visiting expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Apr 16, 2024
1 parent 0e75520 commit 7931cc1
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions crates/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ swc_core = { version = "0.90.33", features = [
"ecma_ast",
"ecma_parser",
"ecma_visit",
"stacker"
] }
serde = "1.0.123"
napi-derive = { version = "2.12.5", optional = true }
Expand Down
3 changes: 2 additions & 1 deletion crates/macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use indexmap::IndexMap;
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
use swc_core::ecma::utils::stack_size::maybe_grow_default;

use swc_core::common::util::take::Take;
use swc_core::common::{SourceMap, Span, DUMMY_SP};
Expand Down Expand Up @@ -247,7 +248,7 @@ impl<'a> Fold for Macros<'a> {
return Expr::Call(call);
}

node.fold_children_with(self)
maybe_grow_default(|| node.fold_children_with(self))
}

fn fold_var_decl(&mut self, mut node: VarDecl) -> VarDecl {
Expand Down
1 change: 1 addition & 0 deletions packages/transformers/js/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ swc_core = { version = "0.90.33", features = [
"ecma_transforms_proposal",
"ecma_transforms_react",
"ecma_transforms_typescript",
"ecma_utils",
"ecma_visit",
"stacker"
] }
Expand Down
3 changes: 2 additions & 1 deletion packages/transformers/js/core/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::collections::{HashMap, HashSet};
use swc_core::common::{sync::Lrc, Mark, Span, DUMMY_SP};
use swc_core::ecma::ast::*;
use swc_core::ecma::atoms::{js_word, JsWord};
use swc_core::ecma::utils::stack_size::maybe_grow_default;
use swc_core::ecma::visit::{noop_visit_type, Visit, VisitWith};

macro_rules! collect_visit_fn {
Expand Down Expand Up @@ -773,7 +774,7 @@ impl Visit for Collect {
}
}
_ => {
node.visit_children_with(self);
maybe_grow_default(|| node.visit_children_with(self));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/transformers/js/core/src/dependency_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use path_slash::PathBufExt;
use std::collections::HashMap;
use std::fmt;
use std::path::Path;
use swc_core::ecma::utils::stack_size::maybe_grow_default;

use serde::{Deserialize, Serialize};
use swc_core::common::{Mark, SourceMap, Span, DUMMY_SP};
Expand Down Expand Up @@ -877,7 +878,7 @@ impl<'a> Fold for DependencyCollector<'a> {
return ast::Expr::Ident(get_undefined_ident(self.unresolved_mark));
}

node.fold_children_with(self)
maybe_grow_default(|| node.fold_children_with(self))
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/transformers/js/core/src/env_replacer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::vec;
use swc_core::common::{Mark, DUMMY_SP};
use swc_core::ecma::ast;
use swc_core::ecma::atoms::JsWord;
use swc_core::ecma::utils::stack_size::maybe_grow_default;
use swc_core::ecma::visit::{Fold, FoldWith};

use crate::utils::*;
Expand Down Expand Up @@ -163,7 +164,7 @@ impl<'a> Fold for EnvReplacer<'a> {
}
}

node.fold_children_with(self)
maybe_grow_default(|| node.fold_children_with(self))
}

fn fold_var_decl(&mut self, node: VarDecl) -> VarDecl {
Expand Down
5 changes: 3 additions & 2 deletions packages/transformers/js/core/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::path::{Path, PathBuf};
use swc_core::common::{Mark, Span, DUMMY_SP};
use swc_core::ecma::ast::*;
use swc_core::ecma::atoms::JsWord;
use swc_core::ecma::utils::stack_size::maybe_grow_default;
use swc_core::ecma::visit::{Fold, FoldWith, VisitWith};

pub fn inline_fs<'a>(
Expand Down Expand Up @@ -61,7 +62,7 @@ impl<'a> Fold for InlineFS<'a> {
}
}

node.fold_children_with(self)
maybe_grow_default(|| node.fold_children_with(self))
}
}

Expand Down Expand Up @@ -218,7 +219,7 @@ struct Evaluator<'a> {

impl<'a> Fold for Evaluator<'a> {
fn fold_expr(&mut self, node: Expr) -> Expr {
let node = node.fold_children_with(self);
let node = maybe_grow_default(|| node.fold_children_with(self));

match &node {
Expr::Ident(ident) => match ident.sym.to_string().as_str() {
Expand Down
3 changes: 2 additions & 1 deletion packages/transformers/js/core/src/global_replacer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use indexmap::IndexMap;
use path_slash::PathBufExt;
use std::path::Path;
use swc_core::ecma::utils::stack_size::maybe_grow_default;

use swc_core::common::{Mark, SourceMap, SyntaxContext, DUMMY_SP};
use swc_core::ecma::ast::{self, ComputedPropName};
Expand Down Expand Up @@ -43,7 +44,7 @@ impl<'a> Fold for GlobalReplacer<'a> {
})
}
}
_ => node.fold_children_with(self),
_ => maybe_grow_default(|| node.fold_children_with(self)),
};

if let Ident(id) = &mut node {
Expand Down
3 changes: 2 additions & 1 deletion packages/transformers/js/core/src/hoist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::hash::Hasher;
use swc_core::common::{Mark, Span, SyntaxContext, DUMMY_SP};
use swc_core::ecma::ast::*;
use swc_core::ecma::atoms::{js_word, JsWord};
use swc_core::ecma::utils::stack_size::maybe_grow_default;
use swc_core::ecma::visit::{Fold, FoldWith};

use crate::id;
Expand Down Expand Up @@ -740,7 +741,7 @@ impl<'a> Fold for Hoist<'a> {
_ => {}
}

node.fold_children_with(self)
maybe_grow_default(|| node.fold_children_with(self))
}

fn fold_seq_expr(&mut self, node: SeqExpr) -> SeqExpr {
Expand Down
3 changes: 2 additions & 1 deletion packages/transformers/js/core/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use swc_core::common::{Mark, Span, SyntaxContext, DUMMY_SP};
use swc_core::ecma::ast::*;
use swc_core::ecma::atoms::{js_word, JsWord};
use swc_core::ecma::preset_env::{Feature, Versions};
use swc_core::ecma::utils::stack_size::maybe_grow_default;
use swc_core::ecma::visit::{Fold, FoldWith};

use crate::fold_member_expr_skip_prop;
Expand Down Expand Up @@ -613,7 +614,7 @@ impl Fold for ESMFold {
node
}
}
_ => node.fold_children_with(self),
_ => maybe_grow_default(|| node.fold_children_with(self)),
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/transformers/js/core/src/node_replacer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::path::Path;
use swc_core::common::{Mark, SourceMap, SyntaxContext, DUMMY_SP};
use swc_core::ecma::ast;
use swc_core::ecma::atoms::JsWord;
use swc_core::ecma::utils::stack_size::maybe_grow_default;
use swc_core::ecma::visit::{Fold, FoldWith};

use crate::dependency_collector::{DependencyDescriptor, DependencyKind};
Expand Down Expand Up @@ -44,7 +45,7 @@ impl<'a> Fold for NodeReplacer<'a> {
})
}
}
_ => node.fold_children_with(self),
_ => maybe_grow_default(|| node.fold_children_with(self)),
};

if let Ident(id) = &mut node {
Expand Down
4 changes: 3 additions & 1 deletion packages/transformers/js/core/src/typeof_replacer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::utils::is_unresolved;
use swc_core::common::Mark;
use swc_core::ecma::ast::{Expr, Lit, Str, UnaryOp};
use swc_core::ecma::atoms::js_word;
use swc_core::ecma::utils::stack_size::maybe_grow_default;
use swc_core::ecma::visit::{Fold, FoldWith};

pub struct TypeofReplacer {
Expand Down Expand Up @@ -40,6 +41,7 @@ impl Fold for TypeofReplacer {
}
}
}
node.fold_children_with(self)

maybe_grow_default(|| node.fold_children_with(self))
}
}

0 comments on commit 7931cc1

Please sign in to comment.