mirror of
https://github.com/swc-project/swc.git
synced 2024-12-29 00:23:10 +03:00
test(es/minifier): Fix test system (#4571)
This commit is contained in:
parent
b6136f80e4
commit
bf5ee018b3
@ -41,7 +41,6 @@ destructuring/destructuring_dont_evaluate_with_undefined_as_default_assignment/i
|
||||
drop_unused/keep_assign/input.js
|
||||
drop_unused/reassign_const/input.js
|
||||
drop_unused/var_catch_toplevel/input.js
|
||||
drop_unused/variable_refs_outside_unused_class/input.js
|
||||
evaluate/issue_2535_1/input.js
|
||||
expansions/avoid_spread_getset_object/input.js
|
||||
expansions/avoid_spread_hole/input.js
|
||||
@ -68,7 +67,6 @@ hoist_props/issue_851_hoist_to_conflicting_name/input.js
|
||||
if_return/if_return_same_value/input.js
|
||||
if_return/if_var_return/input.js
|
||||
if_return/issue_2747/input.js
|
||||
inline/dont_inline_funcs_into_default_param/input.js
|
||||
inline/dont_inline_funcs_into_default_param_2/input.js
|
||||
inline/inline_into_scope_conflict/input.js
|
||||
inline/inline_within_extends_1/input.js
|
||||
@ -80,7 +78,6 @@ issue_1443/keep_fnames/input.js
|
||||
issue_1443/unsafe_undefined/input.js
|
||||
issue_1733/function_catch_catch/input.js
|
||||
issue_1750/case_1/input.js
|
||||
issue_1750/case_2/input.js
|
||||
issue_281/collapse_vars_constants/input.js
|
||||
issue_281/inner_var_for_in_1/input.js
|
||||
issue_281/issue_1758/input.js
|
||||
@ -117,24 +114,7 @@ properties/native_prototype/input.js
|
||||
properties/new_this/input.js
|
||||
properties/skip_undeclared_properties_by_default/input.js
|
||||
properties/unsafe_methods_regex/input.js
|
||||
pure_funcs/issue_3065_1/input.js
|
||||
pure_funcs/issue_3065_2/input.js
|
||||
pure_funcs/issue_3065_2b/input.js
|
||||
pure_funcs/unary/input.js
|
||||
pure_getters/issue_2265_3/input.js
|
||||
pure_getters/set_immutable_3/input.js
|
||||
pure_getters/set_immutable_5/input.js
|
||||
pure_getters/strict_reduce_vars/input.js
|
||||
pure_getters/unsafe/input.js
|
||||
pure_getters/unsafe_reduce_vars/input.js
|
||||
reduce_vars/defun_inline_2/input.js
|
||||
reduce_vars/defun_reference/input.js
|
||||
reduce_vars/escaped_prop_1/input.js
|
||||
reduce_vars/escaped_prop_2/input.js
|
||||
reduce_vars/issue_294/input.js
|
||||
reduce_vars/issue_308/input.js
|
||||
reduce_vars/issue_432_1/input.js
|
||||
reduce_vars/issue_432_2/input.js
|
||||
reduce_vars/issue_639/input.js
|
||||
reduce_vars/variables_collision_in_immediately_invoked_func/input.js
|
||||
return_undefined/return_undefined/input.js
|
||||
|
@ -258,7 +258,13 @@ fn run(
|
||||
fn stdout_of(code: &str) -> Result<String, Error> {
|
||||
let actual_output = Command::new("node")
|
||||
.arg("-e")
|
||||
.arg(&code)
|
||||
.arg(&format!(
|
||||
"
|
||||
{}
|
||||
{}",
|
||||
include_str!("./terser_exec_base.js"),
|
||||
code
|
||||
))
|
||||
.output()
|
||||
.context("failed to execute output of minifier")?;
|
||||
|
||||
@ -464,6 +470,66 @@ fn fixture(input: PathBuf) {
|
||||
|
||||
print(cm.clone(), &[expected], false, false)
|
||||
};
|
||||
{
|
||||
// Check output.teraer.js
|
||||
let identical = (|| -> Option<()> {
|
||||
let expected = {
|
||||
let expected = read_to_string(&dir.join("output.terser.js")).ok()?;
|
||||
let fm = cm.new_source_file(FileName::Anon, expected);
|
||||
let lexer = Lexer::new(
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
SourceFileInput::from(&*fm),
|
||||
None,
|
||||
);
|
||||
let mut parser = Parser::new_from(lexer);
|
||||
let expected = parser
|
||||
.parse_module()
|
||||
.map_err(|err| {
|
||||
err.into_diagnostic(&handler).emit();
|
||||
})
|
||||
.ok()?;
|
||||
let mut expected = expected.fold_with(&mut fixer(None));
|
||||
expected = drop_span(expected);
|
||||
expected
|
||||
.body
|
||||
.retain(|s| !matches!(s, ModuleItem::Stmt(Stmt::Empty(..))));
|
||||
|
||||
let mut normalized_expected = expected.clone();
|
||||
normalized_expected.visit_mut_with(&mut DropParens);
|
||||
|
||||
let mut actual = output_module.clone();
|
||||
actual.visit_mut_with(&mut DropParens);
|
||||
|
||||
if actual.eq_ignore_span(&normalized_expected)
|
||||
|| drop_span(actual.clone()) == normalized_expected
|
||||
{
|
||||
return Some(());
|
||||
}
|
||||
|
||||
if print(cm.clone(), &[actual], false, false)
|
||||
== print(cm.clone(), &[normalized_expected], false, false)
|
||||
{
|
||||
return Some(());
|
||||
}
|
||||
|
||||
print(cm.clone(), &[expected], false, false)
|
||||
};
|
||||
|
||||
if output == expected {
|
||||
return Some(());
|
||||
}
|
||||
|
||||
None
|
||||
})()
|
||||
.is_some();
|
||||
if identical {
|
||||
let s = read_to_string(&dir.join("output.terser.js"))
|
||||
.expect("failed to read output.terser.js");
|
||||
std::fs::write(&dir.join("output.js"), s.as_bytes())
|
||||
.expect("failed to update output.js");
|
||||
}
|
||||
}
|
||||
|
||||
if output == expected {
|
||||
return Ok(());
|
||||
|
@ -54,6 +54,7 @@ async/async_arrow_iife_negate_iife/input.js
|
||||
async/async_arrow_wait/input.js
|
||||
async/async_class/input.js
|
||||
async/async_export/input.js
|
||||
async/async_function_declaration/input.js
|
||||
async/async_function_expression/input.js
|
||||
async/async_generator_class_method/input.js
|
||||
async/async_generator_function/input.js
|
||||
@ -428,6 +429,7 @@ drop_unused/unused_var_in_catch/input.js
|
||||
drop_unused/used_block_decls_in_catch/input.js
|
||||
drop_unused/used_var_in_catch/input.js
|
||||
drop_unused/vardef_value/input.js
|
||||
drop_unused/variable_refs_outside_unused_class/input.js
|
||||
evaluate/Infinity_NaN_undefined_LHS/input.js
|
||||
evaluate/and/input.js
|
||||
evaluate/array_slice_index/input.js
|
||||
@ -686,6 +688,7 @@ if_return/issue_1317/input.js
|
||||
if_return/issue_1317_strict/input.js
|
||||
if_return/issue_1437/input.js
|
||||
if_return/issue_1437_conditionals/input.js
|
||||
inline/dont_inline_funcs_into_default_param/input.js
|
||||
inline/inline_annotation_2/input.js
|
||||
inline/inline_func_with_name_existing_in_block_scope/input.js
|
||||
inline/inline_into_scope_conflict_enclosed/input.js
|
||||
@ -731,9 +734,11 @@ issue_1704/mangle_catch/input.js
|
||||
issue_1704/mangle_catch_ie8/input.js
|
||||
issue_1704/mangle_catch_ie8_toplevel/input.js
|
||||
issue_1704/mangle_catch_redef_1/input.js
|
||||
issue_1704/mangle_catch_redef_1_ie8/input.js
|
||||
issue_1704/mangle_catch_redef_1_ie8_toplevel/input.js
|
||||
issue_1704/mangle_catch_redef_1_toplevel/input.js
|
||||
issue_1704/mangle_catch_redef_2/input.js
|
||||
issue_1704/mangle_catch_redef_2_ie8/input.js
|
||||
issue_1704/mangle_catch_redef_2_ie8_toplevel/input.js
|
||||
issue_1704/mangle_catch_redef_2_toplevel/input.js
|
||||
issue_1704/mangle_catch_redef_3/input.js
|
||||
@ -746,6 +751,7 @@ issue_1704/mangle_catch_var_ie8/input.js
|
||||
issue_1704/mangle_catch_var_ie8_toplevel/input.js
|
||||
issue_1704/mangle_catch_var_toplevel/input.js
|
||||
issue_1733/function_catch_catch_ie8/input.js
|
||||
issue_1750/case_2/input.js
|
||||
issue_1787/unary_prefix/input.js
|
||||
issue_1833/iife_for/input.js
|
||||
issue_1833/iife_for_in/input.js
|
||||
@ -978,6 +984,7 @@ properties/accessor_number/input.js
|
||||
properties/accessor_string/input.js
|
||||
properties/accessor_this/input.js
|
||||
properties/array_hole/input.js
|
||||
properties/computed_property/input.js
|
||||
properties/dot_properties_es5/input.js
|
||||
properties/evaluate_string_length/input.js
|
||||
properties/first_256_chars_as_properties/input.js
|
||||
@ -1154,9 +1161,12 @@ reduce_vars/issue_3140_3/input.js
|
||||
reduce_vars/issue_3140_5/input.js
|
||||
reduce_vars/issue_369/input.js
|
||||
reduce_vars/issue_379/input.js
|
||||
reduce_vars/issue_432_1/input.js
|
||||
reduce_vars/issue_432_2/input.js
|
||||
reduce_vars/issue_443/input.js
|
||||
reduce_vars/issue_581/input.js
|
||||
reduce_vars/issue_581_2/input.js
|
||||
reduce_vars/issue_639/input.js
|
||||
reduce_vars/issue_741_2/input.js
|
||||
reduce_vars/issue_741_reference_cycle/input.js
|
||||
reduce_vars/method_1/input.js
|
||||
@ -1219,9 +1229,11 @@ rename/mangle_catch/input.js
|
||||
rename/mangle_catch_ie8/input.js
|
||||
rename/mangle_catch_ie8_toplevel/input.js
|
||||
rename/mangle_catch_redef_1/input.js
|
||||
rename/mangle_catch_redef_1_ie8/input.js
|
||||
rename/mangle_catch_redef_1_ie8_toplevel/input.js
|
||||
rename/mangle_catch_redef_1_toplevel/input.js
|
||||
rename/mangle_catch_redef_2/input.js
|
||||
rename/mangle_catch_redef_2_ie8/input.js
|
||||
rename/mangle_catch_redef_2_ie8_toplevel/input.js
|
||||
rename/mangle_catch_redef_2_toplevel/input.js
|
||||
rename/mangle_catch_toplevel/input.js
|
||||
|
@ -19,7 +19,6 @@ arrow/issue_2136_3/input.js
|
||||
arrow/issue_27/input.js
|
||||
ascii/ascii_only_false/input.js
|
||||
ascii/ascii_only_true/input.js
|
||||
async/async_function_declaration/input.js
|
||||
async/async_inline/input.js
|
||||
block_scope/issue_334/input.js
|
||||
class_properties/class_expression_constant/input.js
|
||||
@ -343,8 +342,6 @@ issue_1588/unsafe_undefined/input.js
|
||||
issue_1639/issue_1639_1/input.js
|
||||
issue_1639/issue_1639_2/input.js
|
||||
issue_1673/side_effects_else/input.js
|
||||
issue_1704/mangle_catch_redef_1_ie8/input.js
|
||||
issue_1704/mangle_catch_redef_2_ie8/input.js
|
||||
issue_1733/function_iife_catch/input.js
|
||||
issue_1733/function_iife_catch_ie8/input.js
|
||||
issue_1770/mangle_props/input.js
|
||||
@ -422,7 +419,6 @@ object/prop_func_to_concise_method/input.js
|
||||
object/prop_func_to_concise_method_various/input.js
|
||||
parameters/default_arguments/input.js
|
||||
parameters/destructuring_arguments_3/input.js
|
||||
properties/computed_property/input.js
|
||||
properties/const_prop_assign_pure/input.js
|
||||
properties/const_prop_assign_strict/input.js
|
||||
properties/dont_mangle_computed_property_1/input.js
|
||||
@ -478,6 +474,9 @@ pure_funcs/issue_2705_3/input.js
|
||||
pure_funcs/issue_2705_4/input.js
|
||||
pure_funcs/issue_2705_5/input.js
|
||||
pure_funcs/issue_2705_6/input.js
|
||||
pure_funcs/issue_3065_1/input.js
|
||||
pure_funcs/issue_3065_2/input.js
|
||||
pure_funcs/issue_3065_2b/input.js
|
||||
pure_funcs/issue_3065_3/input.js
|
||||
pure_funcs/issue_3065_4/input.js
|
||||
pure_funcs/issue_526_1/input.js
|
||||
@ -493,9 +492,14 @@ pure_getters/issue_2838/input.js
|
||||
pure_getters/issue_2938_3/input.js
|
||||
pure_getters/issue_2938_4/input.js
|
||||
pure_getters/set_immutable_1/input.js
|
||||
pure_getters/set_immutable_3/input.js
|
||||
pure_getters/set_immutable_5/input.js
|
||||
pure_getters/set_immutable_6/input.js
|
||||
pure_getters/set_mutable_1/input.js
|
||||
pure_getters/set_mutable_2/input.js
|
||||
pure_getters/strict_reduce_vars/input.js
|
||||
pure_getters/unsafe/input.js
|
||||
pure_getters/unsafe_reduce_vars/input.js
|
||||
reduce_vars/array_forin_1/input.js
|
||||
reduce_vars/chained_assignments/input.js
|
||||
reduce_vars/conditional_chain_certain_part/input.js
|
||||
@ -504,15 +508,19 @@ reduce_vars/defun_catch_2/input.js
|
||||
reduce_vars/defun_catch_3/input.js
|
||||
reduce_vars/defun_catch_6/input.js
|
||||
reduce_vars/defun_inline_1/input.js
|
||||
reduce_vars/defun_inline_2/input.js
|
||||
reduce_vars/defun_inline_3/input.js
|
||||
reduce_vars/defun_label/input.js
|
||||
reduce_vars/defun_redefine/input.js
|
||||
reduce_vars/defun_reference/input.js
|
||||
reduce_vars/defun_var_1/input.js
|
||||
reduce_vars/defun_var_2/input.js
|
||||
reduce_vars/delay_def/input.js
|
||||
reduce_vars/duplicate_lambda_defun_name_1/input.js
|
||||
reduce_vars/escape_expansion/input.js
|
||||
reduce_vars/escape_local_sequence/input.js
|
||||
reduce_vars/escaped_prop_1/input.js
|
||||
reduce_vars/escaped_prop_2/input.js
|
||||
reduce_vars/func_arg_1/input.js
|
||||
reduce_vars/func_arg_2/input.js
|
||||
reduce_vars/func_modified/input.js
|
||||
@ -534,6 +542,8 @@ reduce_vars/issue_2774/input.js
|
||||
reduce_vars/issue_2799_2/input.js
|
||||
reduce_vars/issue_2836/input.js
|
||||
reduce_vars/issue_2860_2/input.js
|
||||
reduce_vars/issue_294/input.js
|
||||
reduce_vars/issue_308/input.js
|
||||
reduce_vars/issue_3110_3/input.js
|
||||
reduce_vars/issue_3113_1/input.js
|
||||
reduce_vars/issue_3113_2/input.js
|
||||
@ -572,8 +582,6 @@ reduce_vars/var_assign_2/input.js
|
||||
regexp/unsafe_slashes/input.js
|
||||
rename/function_iife_catch/input.js
|
||||
rename/function_iife_catch_ie8/input.js
|
||||
rename/mangle_catch_redef_1_ie8/input.js
|
||||
rename/mangle_catch_redef_2_ie8/input.js
|
||||
rename/mangle_catch_var/input.js
|
||||
sequences/cascade_assignment_in_return/input.js
|
||||
sequences/delete_seq_4/input.js
|
||||
|
@ -1,6 +1,6 @@
|
||||
async function f0() {}
|
||||
async function f1() {
|
||||
await x;
|
||||
await x, y;
|
||||
}
|
||||
async function f2() {
|
||||
await (x + y);
|
||||
@ -9,7 +9,7 @@ async function f3() {
|
||||
await x, await y;
|
||||
}
|
||||
async function f4() {
|
||||
(await x) + (await y);
|
||||
await (x + (await y));
|
||||
}
|
||||
async function f5() {
|
||||
await x;
|
||||
|
@ -2,6 +2,6 @@ var a = "PASS";
|
||||
try {
|
||||
throw "FAIL1";
|
||||
} catch (a) {
|
||||
var b = "FAIL2";
|
||||
var a = "FAIL2";
|
||||
}
|
||||
console.log(a);
|
||||
|
@ -1,6 +1,6 @@
|
||||
try {
|
||||
throw "FAIL1";
|
||||
} catch (a) {
|
||||
var b = "FAIL2";
|
||||
var a = "FAIL2";
|
||||
}
|
||||
console.log(a);
|
||||
|
@ -1,7 +1,4 @@
|
||||
var a = 0,
|
||||
b = 1;
|
||||
switch (true) {
|
||||
case a || true:
|
||||
b = 2;
|
||||
}
|
||||
if (true === (a || true)) b = 2;
|
||||
console.log(a, b);
|
||||
|
@ -1,7 +1,4 @@
|
||||
var a = 0,
|
||||
b = 1;
|
||||
switch (0) {
|
||||
case a:
|
||||
a = 3;
|
||||
}
|
||||
if (0 === a) a = 3;
|
||||
console.log(a, b);
|
||||
|
@ -1 +1 @@
|
||||
console.log(["bar", console.log("foo")][0]);
|
||||
console.log({ a: "bar", [console.log("foo")]: 42 }.a);
|
||||
|
@ -2,6 +2,6 @@ var a = "PASS";
|
||||
try {
|
||||
throw "FAIL1";
|
||||
} catch (a) {
|
||||
var b = "FAIL2";
|
||||
var a = "FAIL2";
|
||||
}
|
||||
console.log(a);
|
||||
|
@ -1,6 +1,6 @@
|
||||
try {
|
||||
throw "FAIL1";
|
||||
} catch (a) {
|
||||
var b = "FAIL2";
|
||||
var a = "FAIL2";
|
||||
}
|
||||
console.log(a);
|
||||
|
@ -259,7 +259,13 @@ fn stdout_of(code: &str, timeout: Duration) -> Result<String, Error> {
|
||||
let res = (|| {
|
||||
let actual_output = Command::new("node")
|
||||
.arg("-e")
|
||||
.arg(&code)
|
||||
.arg(format!(
|
||||
"
|
||||
{}
|
||||
{}",
|
||||
include_str!("./terser_exec_base.js"),
|
||||
code
|
||||
))
|
||||
.output()
|
||||
.context("failed to execute output of minifier")?;
|
||||
|
||||
|
2
crates/swc_ecma_minifier/tests/terser_exec_base.js
Normal file
2
crates/swc_ecma_minifier/tests/terser_exec_base.js
Normal file
@ -0,0 +1,2 @@
|
||||
global.id = (v) => v;
|
||||
global.leak = (cb) => cb;
|
Loading…
Reference in New Issue
Block a user