Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(es/transforms): Allocate stacks dynamically #8867

Merged
merged 37 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/swc_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ common_plugin_transform = [
css_plugin_transform = ["common_plugin_transform", "__css_plugin_transform"]
ecma_plugin_transform = ["common_plugin_transform", "__ecma_plugin_transform"]

# Use `stacker` to avoid stack overflow.
stacker = ["swc_ecma_parser/stacker", "swc_ecma_utils/stacker"]

# Host features to enable plugin `runner` runtime.
# native feature is for the host environment does not have, or cannot access
# to the wasm runtime (i.e cli, or @swc/core node bindings).
Expand Down
6 changes: 5 additions & 1 deletion crates/swc_ecma_minifier/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::Instant;
use rustc_hash::FxHashSet;
use swc_common::{util::take::Take, Mark, Span, Spanned, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_utils::{ModuleItemLike, StmtLike, Value};
use swc_ecma_utils::{stack_size::maybe_grow_default, ModuleItemLike, StmtLike, Value};
use swc_ecma_visit::{noop_visit_type, visit_obj_and_computed, Visit, VisitWith};

pub(crate) mod base54;
Expand Down Expand Up @@ -510,6 +510,10 @@ impl Visit for EvalFinder {

visit_obj_and_computed!();

fn visit_expr(&mut self, n: &Expr) {
maybe_grow_default(|| n.visit_children_with(self));
}

fn visit_ident(&mut self, i: &Ident) {
if i.sym == "eval" {
self.found = true;
Expand Down
55 changes: 55 additions & 0 deletions crates/swc_ecma_transforms/tests/deno.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#![cfg(all(
feature = "swc_ecma_transforms_proposal",
feature = "swc_ecma_transforms_typescript",
))]
use std::path::PathBuf;

use swc_common::{chain, Mark};
use swc_ecma_parser::Syntax;
use swc_ecma_transforms::{fixer, helpers::inject_helpers, hygiene, resolver};
use swc_ecma_transforms_proposal::{
decorator_2022_03::decorator_2022_03,
explicit_resource_management::explicit_resource_management,
};
use swc_ecma_transforms_testing::test_fixture;
use swc_ecma_transforms_typescript::typescript;

#[testing::fixture("tests/fixture/deno/**/input.ts")]
fn stack_overflow(input: PathBuf) {
run_test(input);
}

fn run_test(input: PathBuf) {
let output = input.with_file_name("output.js");

test_fixture(
Syntax::Typescript(Default::default()),
&|_tester| {
let unresolved_mark = Mark::new();
let top_level_mark = Mark::new();

chain!(
resolver(unresolved_mark, top_level_mark, true),
decorator_2022_03(),
explicit_resource_management(),
inject_helpers(top_level_mark),
typescript(
typescript::Config {
verbatim_module_syntax: false,
import_not_used_as_values: typescript::ImportsNotUsedAsValues::Remove,
no_empty_export: true,
import_export_assign_config:
typescript::TsImportExportAssignConfig::Preserve,
ts_enum_is_mutable: true,
},
top_level_mark
),
fixer(None),
hygiene(),
)
},
&input,
&output,
Default::default(),
)
}
Loading
Loading