From 79f87e03db1063c645fba36c1ba6ba673127bad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Thu, 12 May 2022 16:28:52 +0900 Subject: [PATCH] test(es/minifier): Execute more tests (#4636) --- .../src/compress/optimize/inline.rs | 2 +- crates/swc_ecma_minifier/tests/TODO.txt | 7 ---- crates/swc_ecma_minifier/tests/postponed.txt | 7 ++++ crates/swc_ecma_minifier/tests/terser_exec.rs | 35 +++++++++++++------ .../tests/resolver/minifier/12/input.js | 6 ++++ .../tests/resolver/minifier/12/output.js | 6 ++++ 6 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 crates/swc_ecma_transforms_base/tests/resolver/minifier/12/input.js create mode 100644 crates/swc_ecma_transforms_base/tests/resolver/minifier/12/output.js diff --git a/crates/swc_ecma_minifier/src/compress/optimize/inline.rs b/crates/swc_ecma_minifier/src/compress/optimize/inline.rs index 32d306a384c..1d7a8856d26 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/inline.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/inline.rs @@ -633,7 +633,7 @@ where } self.changed = true; - report_change!("inline: Replacing a variable with cheap expression"); + report_change!("inline: Replacing a variable `{}` with cheap expression", i); *e = *value; return; diff --git a/crates/swc_ecma_minifier/tests/TODO.txt b/crates/swc_ecma_minifier/tests/TODO.txt index 37e825fd418..67947a0f71c 100644 --- a/crates/swc_ecma_minifier/tests/TODO.txt +++ b/crates/swc_ecma_minifier/tests/TODO.txt @@ -11,9 +11,6 @@ drop_unused/keep_assign/input.js drop_unused/reassign_const/input.js drop_unused/var_catch_toplevel/input.js evaluate/issue_2535_1/input.js -expansions/avoid_spread_getset_object/input.js -expansions/avoid_spread_hole/input.js -functions/avoid_generating_duplicate_functions_compared_together_3/input.js harmony/array_literal_with_spread_4a/input.js harmony/default_assign/input.js if_return/if_var_return/input.js @@ -23,12 +20,8 @@ issue_1034/non_hoisted_function_after_return_2a/input.js issue_1034/non_hoisted_function_after_return_2b/input.js issue_1052/defun_else_if_return/input.js issue_1052/defun_if_return/input.js -issue_1443/keep_fnames/input.js -issue_1443/unsafe_undefined/input.js issue_281/inner_var_for_in_1/input.js issue_368/collapse/input.js -issue_417/test_unexpected_crash/input.js -issue_417/test_unexpected_crash_2/input.js nullish/conditional_to_nullish_coalescing_2/input.js parameters/destructuring_arguments_2/input.js properties/dot_properties/input.js diff --git a/crates/swc_ecma_minifier/tests/postponed.txt b/crates/swc_ecma_minifier/tests/postponed.txt index 404bfbf1e7c..c2dd24e0311 100644 --- a/crates/swc_ecma_minifier/tests/postponed.txt +++ b/crates/swc_ecma_minifier/tests/postponed.txt @@ -194,6 +194,8 @@ evaluate/unsafe_object/input.js evaluate/unsafe_object_complex/input.js evaluate/unsafe_object_nested/input.js evaluate/unsafe_object_repeated/input.js +expansions/avoid_spread_getset_object/input.js +expansions/avoid_spread_hole/input.js export/export_default_named_async_function/input.js export/export_default_named_generator/input.js export/issue_2126/input.js @@ -210,6 +212,7 @@ export/name_cache_import_star_as_name_from_module/input.js export/name_cache_mangle_export_default_class/input.js export/name_cache_mangle_export_default_function/input.js export/name_cache_mangle_local_import_and_export_aliases/input.js +functions/avoid_generating_duplicate_functions_compared_together_3/input.js functions/duplicate_arg_var/input.js functions/empty_body/input.js functions/hoist_funs/input.js @@ -366,6 +369,8 @@ issue_1431/level_one/input.js issue_1431/level_three/input.js issue_1431/level_two/input.js issue_1431/level_zero/input.js +issue_1443/keep_fnames/input.js +issue_1443/unsafe_undefined/input.js issue_1446/typeof_eq_undefined_ie8/input.js issue_1446/undefined_redefined_mangle/input.js issue_1447/conditional_false_stray_else_in_loop/input.js @@ -410,6 +415,8 @@ issue_2719/warn/input.js issue_281/collapse_vars_constants/input.js issue_281/issue_1758/input.js issue_2871/comparison_with_undefined/input.js +issue_417/test_unexpected_crash/input.js +issue_417/test_unexpected_crash_2/input.js issue_44/issue_44_valid_ast_1/input.js issue_44/issue_44_valid_ast_2/input.js issue_597/issue_1724/input.js diff --git a/crates/swc_ecma_minifier/tests/terser_exec.rs b/crates/swc_ecma_minifier/tests/terser_exec.rs index 2c4c21fa4be..08d206d3aea 100644 --- a/crates/swc_ecma_minifier/tests/terser_exec.rs +++ b/crates/swc_ecma_minifier/tests/terser_exec.rs @@ -34,6 +34,9 @@ use testing::assert_eq; #[testing::fixture( "tests/terser/compress/**/input.js", exclude( + "expansions/avoid_spread_getset_object/", + "expansions/avoid_spread_hole/", + "functions/avoid_generating_duplicate_functions_compared_together_3/", // We don't care about ie8 "ie8", // tests with infinite loops @@ -69,13 +72,21 @@ fn terser_exec(input: PathBuf) { return Ok(()); } - let expected_src = read_to_string(&dir.join("output.terser.js")).map_err(|_| { - eprintln!("This test does not have `output.terser.js`"); - })?; + let mut expected_src = None; - let expected_stdout = - stdout_of(&expected_src, Duration::from_millis(500)).map_err(|_| { - eprintln!("This test is not executable test"); + let expected_stdout = read_to_string(&dir.join("expected.stdout")) + .or_else(|_| { + let src = read_to_string(&dir.join("output.terser.js")) + .context("This test does not have `output.terser.js`")?; + + expected_src = Some(src.clone()); + + stdout_of(&src, Duration::from_millis(500)) + .context("This test is not executable test") + }) + .context("This test is not an excutable test") + .map_err(|err| { + eprintln!("{}", err); })?; if input_stdout != expected_stdout { @@ -94,11 +105,13 @@ fn terser_exec(input: PathBuf) { let actual = print(cm, &[output_module], false, false); let actual_stdout = stdout_of(&actual, Duration::from_secs(5)).unwrap(); - eprintln!( - "---- {} -----\n{}", - Color::Green.paint("Expected"), - expected_src - ); + if let Some(expected_src) = expected_src { + eprintln!( + "---- {} -----\n{}", + Color::Green.paint("Expected"), + expected_src + ); + } eprintln!("---- {} -----\n{}", Color::Green.paint("Actual"), actual); diff --git a/crates/swc_ecma_transforms_base/tests/resolver/minifier/12/input.js b/crates/swc_ecma_transforms_base/tests/resolver/minifier/12/input.js new file mode 100644 index 00000000000..a81b73d53a4 --- /dev/null +++ b/crates/swc_ecma_transforms_base/tests/resolver/minifier/12/input.js @@ -0,0 +1,6 @@ +function f(undefined) { + return function () { + if (a) return b; + if (c) return d; + }; +} diff --git a/crates/swc_ecma_transforms_base/tests/resolver/minifier/12/output.js b/crates/swc_ecma_transforms_base/tests/resolver/minifier/12/output.js new file mode 100644 index 00000000000..3e87737766e --- /dev/null +++ b/crates/swc_ecma_transforms_base/tests/resolver/minifier/12/output.js @@ -0,0 +1,6 @@ +function f__1(undefined__2) { + return function() { + if (a) return b; + if (c) return d; + }; +}