Skip to content

Commit

Permalink
fix(es/testing): Revert #9264 (#9621)
Browse files Browse the repository at this point in the history
Reverts #9264
  • Loading branch information
kdy1 authored Oct 8, 2024
1 parent 128acff commit 85f5e5b
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 420 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-fans-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
swc_ecma_transforms_testing: breaking
---

Revert "feat(es/testing): Parse test code as a `Program` instead of a `Module`"
17 changes: 0 additions & 17 deletions crates/swc_ecma_transforms/tests/decorators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ fn transformation(t: &Tester) -> impl Fold {

// transformation_declaration
test!(
module,
syntax(false),
|t| transformation(t),
transformation_declaration,
Expand All @@ -102,7 +101,6 @@ class A {}
);
// transformation_initialize_after_super_multiple
test!(
module,
syntax(false),
|t| transformation(t),
transformation_initialize_after_super_multiple,
Expand Down Expand Up @@ -136,7 +134,6 @@ export default @dec() class {}
);
// transformation_initialize_after_super_statement
test!(
module,
syntax(false),
|t| transformation(t),
transformation_initialize_after_super_statement,
Expand Down Expand Up @@ -214,7 +211,6 @@ expect(A).toBe(C);
);
// misc_method_name_not_shadow
test!(
module,
syntax(false),
|t| tr(t),
misc_method_name_not_shadow,
Expand Down Expand Up @@ -324,7 +320,6 @@ expect(() => {
);
// duplicated_keys_computed_keys_same_value
test!(
module,
syntax(false),
|t| tr(t),
duplicated_keys_computed_keys_same_value,
Expand Down Expand Up @@ -400,7 +395,6 @@ expect(log).toEqual(numsFrom0to9);
);
// transformation_initializer_after_super_bug_8808
test!(
module,
syntax(false),
|t| transformation(t),
transformation_initiailzer_after_super_bug_8808,
Expand Down Expand Up @@ -440,7 +434,6 @@ expect(A.prototype.method()).toBe(2);
);
// transformation_arguments
test!(
module,
syntax(false),
|t| transformation(t),
transformation_arguments,
Expand Down Expand Up @@ -539,7 +532,6 @@ expect(calls).toBe(1);
// ordering
// transformation_initialize_after_super_expression
test!(
module,
syntax(false),
|t| transformation(t),
transformation_initialize_after_super_expression,
Expand Down Expand Up @@ -911,7 +903,6 @@ expect(Object.getOwnPropertyDescriptor(A.prototype, "foo")).toEqual({
);
// transformation_extends
test!(
module,
syntax(false),
|t| transformation(t),
transformation_extends,
Expand All @@ -923,7 +914,6 @@ test!(
// finishers
// transformation_extends_await
test!(
module,
syntax(false),
|t| transformation(t),
transformation_extends_await,
Expand All @@ -936,7 +926,6 @@ async function g() {
);
// transformation_extends_yield
test!(
module,
syntax(false),
|t| transformation(t),
transformation_extends_yield,
Expand Down Expand Up @@ -1103,7 +1092,6 @@ expect(i).toBe(2);
);
// transformation_initialize_after_super_bug_8931
test!(
module,
syntax(false),
|t| transformation(t),
transformation_initialize_after_super_bug_8931,
Expand Down Expand Up @@ -1330,7 +1318,6 @@ expect(Foo.prototype.bar).toBe(value2);
);
// transformation_expression
test!(
module,
syntax(false),
|t| transformation(t),
transformation_expression,
Expand Down Expand Up @@ -1367,7 +1354,6 @@ expect(A.method()).toBe(2);
// element_descriptors
// duplicated_keys_computed_keys_same_ast
test!(
module,
syntax(false),
|t| tr(t),
duplicated_keys_computed_keys_same_ast,
Expand Down Expand Up @@ -1517,7 +1503,6 @@ expect(desc.set()).toBe(2);
// misc
// transformation_extends_exec
test_exec!(
module,
syntax(false),
|t| tr(t),
transformation_extends_exec,
Expand Down Expand Up @@ -1564,7 +1549,6 @@ expect(() => {
);
// duplicated_keys_computed_keys_same_value_exec
test_exec!(
module,
syntax(false),
|t| tr(t),
duplicated_keys_computed_keys_same_value_exec,
Expand Down Expand Up @@ -3898,7 +3882,6 @@ eval: function () {
);

test!(
module,
ts(),
|_| decorators(Default::default()),
issue_846_1,
Expand Down
5 changes: 2 additions & 3 deletions crates/swc_ecma_transforms_module/tests/amd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use swc_ecma_parser::{Syntax, TsSyntax};
use swc_ecma_transforms_base::{feature::FeatureFlag, resolver};
use swc_ecma_transforms_compat::es2015::for_of;
use swc_ecma_transforms_module::amd::{self, amd};
use swc_ecma_transforms_testing::{test, test_module_fixture};
use swc_ecma_transforms_testing::{test, test_fixture};
use swc_ecma_transforms_typescript::typescript;
use swc_ecma_visit::Fold;

Expand Down Expand Up @@ -60,7 +60,7 @@ fn esm_to_amd(input: PathBuf) {
Err(..) => Default::default(),
};

test_module_fixture(
test_fixture(
if is_ts { ts_syntax() } else { syntax() },
&|t| tr(config.clone(), is_ts, t.comments.clone()),
&input,
Expand All @@ -70,7 +70,6 @@ fn esm_to_amd(input: PathBuf) {
}

test!(
module,
syntax(),
|t| chain!(
for_of(for_of::Config {
Expand Down
5 changes: 2 additions & 3 deletions crates/swc_ecma_transforms_module/tests/common_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use swc_ecma_parser::{Syntax, TsSyntax};
use swc_ecma_transforms_base::{feature::FeatureFlag, resolver};
use swc_ecma_transforms_compat::es2015::for_of;
use swc_ecma_transforms_module::common_js::{self, common_js};
use swc_ecma_transforms_testing::{test, test_module_fixture, FixtureTestConfig};
use swc_ecma_transforms_testing::{test, test_fixture, FixtureTestConfig};
use swc_ecma_transforms_typescript::typescript;
use swc_ecma_visit::Fold;

Expand Down Expand Up @@ -52,7 +52,7 @@ fn esm_to_cjs(input: PathBuf) {
Err(..) => Default::default(),
};

test_module_fixture(
test_fixture(
if is_ts { ts_syntax() } else { syntax() },
&|_| tr(config.clone(), is_ts),
&input,
Expand All @@ -65,7 +65,6 @@ fn esm_to_cjs(input: PathBuf) {
}

test!(
module,
syntax(),
|_| chain!(
for_of(for_of::Config {
Expand Down
6 changes: 3 additions & 3 deletions crates/swc_ecma_transforms_module/tests/path_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use swc_ecma_transforms_module::{
path::{ImportResolver, NodeImportResolver},
rewriter::import_rewriter,
};
use swc_ecma_transforms_testing::test_module_fixture;
use swc_ecma_transforms_testing::test_fixture;
use testing::run_test2;

type TestProvider = NodeImportResolver<NodeModulesResolver>;
Expand Down Expand Up @@ -43,7 +43,7 @@ fn issue_4730() {
let input_dir = dir.join("input");
let output_dir = dir.join("output");

test_module_fixture(
test_fixture(
Syntax::default(),
&|_| {
let mut paths = IndexMap::new();
Expand Down Expand Up @@ -136,7 +136,7 @@ fn fixture(input_dir: PathBuf) {
.canonicalize()
.unwrap();
dbg!(&base_dir);
test_module_fixture(
test_fixture(
Syntax::default(),
&|_| {
let rules = config.paths.clone().into_iter().collect();
Expand Down
10 changes: 2 additions & 8 deletions crates/swc_ecma_transforms_module/tests/system_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use swc_common::{chain, Mark};
use swc_ecma_parser::Syntax;
use swc_ecma_transforms_base::resolver;
use swc_ecma_transforms_module::system_js::{system_js, Config};
use swc_ecma_transforms_testing::{test, test_module_fixture, Tester};
use swc_ecma_transforms_testing::{test, test_fixture, Tester};
use swc_ecma_visit::Fold;

fn syntax() -> Syntax {
Expand All @@ -23,15 +23,13 @@ fn tr(_tester: &mut Tester<'_>, config: Config) -> impl Fold {
}

test!(
module,
syntax(),
|tester| tr(tester, Default::default()),
allow_continuous_assignment,
r#"var e = {}; e.a = e.b = e.c = e.d = e.e = e.f = e.g = e.h = e.i = e.j = e.k = e.l = e.m = e.n = e.o = e.p = e.q = e.r = e.s = e.t = e.u = e.v = e.w = e.x = e.y = e.z = e.A = e.B = e.C = e.D = e.E = e.F = e.G = e.H = e.I = e.J = e.K = e.L = e.M = e.N = e.O = e.P = e.Q = e.R = e.S = void 0;"#
);

test!(
module,
syntax(),
|tester| tr(
tester,
Expand All @@ -45,7 +43,6 @@ test!(
);

test!(
module,
syntax(),
|tester| tr(
tester,
Expand All @@ -63,7 +60,6 @@ test!(
);

test!(
module,
syntax(),
|tester| tr(
tester,
Expand All @@ -86,7 +82,6 @@ test!(
);

test!(
module,
syntax(),
|tester| tr(
tester,
Expand All @@ -104,7 +99,6 @@ test!(
);

test!(
module,
syntax(),
|tester| tr(tester, Default::default()),
imports,
Expand All @@ -123,7 +117,7 @@ fn fixture(input: PathBuf) {

let output = dir.join("output.mjs");

test_module_fixture(
test_fixture(
syntax(),
&|tester| tr(tester, Default::default()),
&input,
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_transforms_module/tests/umd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use swc_common::{chain, Mark};
use swc_ecma_parser::{Syntax, TsSyntax};
use swc_ecma_transforms_base::{feature::FeatureFlag, resolver};
use swc_ecma_transforms_module::umd::{umd, Config};
use swc_ecma_transforms_testing::{test_module_fixture, Tester};
use swc_ecma_transforms_testing::{test_fixture, Tester};
use swc_ecma_transforms_typescript::typescript;
use swc_ecma_visit::Fold;

Expand Down Expand Up @@ -58,7 +58,7 @@ fn esm_to_umd(input: PathBuf) {
Err(..) => Default::default(),
};

test_module_fixture(
test_fixture(
if is_ts { ts_syntax() } else { syntax() },
&|tester| tr(tester, config.clone(), is_ts),
&input,
Expand Down
15 changes: 5 additions & 10 deletions crates/swc_ecma_transforms_optimization/src/inline_globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl VisitMut for InlineGlobals {
#[cfg(test)]
mod tests {
use swc_ecma_transforms_testing::{test, Tester};
use swc_ecma_utils::{DropSpan, StmtOrModuleItem};
use swc_ecma_utils::DropSpan;

use super::*;

Expand All @@ -220,22 +220,17 @@ mod tests {
(*v).into()
};

let v = tester
let mut v = tester
.apply_transform(
as_folder(DropSpan),
"global.js",
::swc_ecma_parser::Syntax::default(),
&v,
)
.unwrap();

let v = match v {
Program::Module(mut m) => m.body.pop().and_then(|x| x.into_stmt().ok()),
Program::Script(mut s) => s.body.pop(),
};
assert!(v.is_some());
let v = match v.unwrap() {
Stmt::Expr(ExprStmt { expr, .. }) => *expr,
assert_eq!(v.body.len(), 1);
let v = match v.body.pop().unwrap() {
ModuleItem::Stmt(Stmt::Expr(ExprStmt { expr, .. })) => *expr,
_ => unreachable!(),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,19 +468,19 @@ impl VisitMut for Inlining<'_> {
self.visit_with_child(ScopeKind::Cond, &mut stmt.alt);
}

fn visit_mut_program(&mut self, program: &mut Program) {
fn visit_mut_module_items(&mut self, items: &mut Vec<ModuleItem>) {
let _tracing = span!(Level::ERROR, "inlining", pass = self.pass).entered();

let old_phase = self.phase;

self.phase = Phase::Analysis;
program.visit_mut_children_with(self);
items.visit_mut_children_with(self);

tracing::trace!("Switching to Inlining phase");

// Inline
self.phase = Phase::Inlining;
program.visit_mut_children_with(self);
items.visit_mut_children_with(self);

self.phase = old_phase;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_transforms_proposal/tests/decorator_evanw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fs, path::PathBuf};

use swc_ecma_parser::{EsSyntax, Syntax};
use swc_ecma_transforms_proposal::decorator_2022_03::decorator_2022_03;
use swc_ecma_transforms_testing::exec_module_tr;
use swc_ecma_transforms_testing::exec_tr;
use swc_ecma_visit::as_folder;

const HELPERS: &str = r###"
Expand Down Expand Up @@ -57,7 +57,7 @@ fn fixture(input: PathBuf) {
{code}"
);

exec_module_tr(
exec_tr(
&input.file_name().unwrap().to_string_lossy(),
Syntax::Es(EsSyntax {
decorators: true,
Expand Down
Loading

0 comments on commit 85f5e5b

Please sign in to comment.