feat(es/minifier): Handle array literals in sequences (#3348)

swc_ecma_minifier:
 - `sequences`: Implement more rules for array literals.
This commit is contained in:
Donny/강동윤 2022-01-24 21:10:20 +09:00 committed by GitHub
parent 438649818f
commit 8007b2dc93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 16 deletions

View File

@ -895,6 +895,16 @@ where
false
}
Expr::Array(e) => {
for elem in e.elems.iter().flatten() {
if !self.is_skippable_for_seq(a, &elem.expr) {
return false;
}
}
true
}
_ => false,
}
}
@ -1059,12 +1069,9 @@ where
return Ok(true);
}
match &*elem.expr {
Expr::Ident(..) => {}
_ => {
// To preserve side-effects, we need to abort.
break;
}
if !self.is_skippable_for_seq(Some(a), &elem.expr) {
// To preserve side-effects, we need to abort.
break;
}
}
None => {}

View File

@ -120,6 +120,7 @@ collapse_vars/collapse_rhs_this/input.js
collapse_vars/collapse_rhs_undefined/input.js
collapse_vars/collapse_rhs_var/input.js
collapse_vars/collapse_rhs_vardef/input.js
collapse_vars/collapse_vars_array/input.js
collapse_vars/collapse_vars_closures/input.js
collapse_vars/collapse_vars_issue_721/input.js
collapse_vars/collapse_vars_properties/input.js
@ -127,6 +128,7 @@ collapse_vars/collapse_vars_regexp/input.js
collapse_vars/collapse_vars_try/input.js
collapse_vars/collapse_vars_unary_2/input.js
collapse_vars/collapse_vars_while/input.js
collapse_vars/compound_assignment/input.js
collapse_vars/cond_branch_switch/input.js
collapse_vars/conditional_1/input.js
collapse_vars/conditional_2/input.js
@ -159,6 +161,9 @@ collapse_vars/issue_2425_1/input.js
collapse_vars/issue_2425_2/input.js
collapse_vars/issue_2425_3/input.js
collapse_vars/issue_2436_12/input.js
collapse_vars/issue_2436_2/input.js
collapse_vars/issue_2436_3/input.js
collapse_vars/issue_2436_5/input.js
collapse_vars/issue_2437_1/input.js
collapse_vars/issue_2437_2/input.js
collapse_vars/issue_2571_1/input.js
@ -380,6 +385,7 @@ evaluate/issue_2231_3/input.js
evaluate/issue_2535_3/input.js
evaluate/issue_2822/input.js
evaluate/issue_2916_1/input.js
evaluate/issue_2916_2/input.js
evaluate/issue_2926_2/input.js
evaluate/issue_2968/input.js
evaluate/negative_zero/input.js
@ -614,6 +620,7 @@ issue_1447/else_with_empty_statement/input.js
issue_1588/runtime_error/input.js
issue_1588/support_ie8/input.js
issue_1609/chained_evaluation_1/input.js
issue_1609/chained_evaluation_2/input.js
issue_1639/issue_1639_3/input.js
issue_1656/f7/input.js
issue_1673/side_effects_catch/input.js
@ -978,6 +985,7 @@ reduce_vars/issue_2455/input.js
reduce_vars/issue_2598/input.js
reduce_vars/issue_2670/input.js
reduce_vars/issue_2869/input.js
reduce_vars/issue_2916/input.js
reduce_vars/issue_2919/input.js
reduce_vars/issue_2992/input.js
reduce_vars/issue_3042_1/input.js

View File

@ -8,7 +8,6 @@ collapse_vars/cascade_conditional/input.js
collapse_vars/cascade_statement/input.js
collapse_vars/cascade_switch/input.js
collapse_vars/collapse_vars_arguments/input.js
collapse_vars/collapse_vars_array/input.js
collapse_vars/collapse_vars_assignment/input.js
collapse_vars/collapse_vars_constants/input.js
collapse_vars/collapse_vars_do_while/input.js
@ -26,7 +25,6 @@ collapse_vars/collapse_vars_side_effects_1/input.js
collapse_vars/collapse_vars_side_effects_2/input.js
collapse_vars/collapse_vars_switch/input.js
collapse_vars/collapse_vars_unary/input.js
collapse_vars/compound_assignment/input.js
collapse_vars/double_def_1/input.js
collapse_vars/double_def_2/input.js
collapse_vars/issue_1537_destructuring_1/input.js
@ -41,10 +39,7 @@ collapse_vars/issue_2364_5/input.js
collapse_vars/issue_2436_1/input.js
collapse_vars/issue_2436_10/input.js
collapse_vars/issue_2436_11/input.js
collapse_vars/issue_2436_2/input.js
collapse_vars/issue_2436_3/input.js
collapse_vars/issue_2436_4/input.js
collapse_vars/issue_2436_5/input.js
collapse_vars/issue_2436_6/input.js
collapse_vars/issue_2436_7/input.js
collapse_vars/issue_2436_8/input.js
@ -129,7 +124,6 @@ drop_unused/variable_refs_outside_unused_class/input.js
evaluate/delete_expr_1/input.js
evaluate/delete_expr_2/input.js
evaluate/issue_2535_1/input.js
evaluate/issue_2916_2/input.js
expansions/avoid_spread_getset_object/input.js
expansions/avoid_spread_hole/input.js
export/export_default_named_async_function/input.js
@ -215,7 +209,6 @@ issue_1443/keep_fnames/input.js
issue_1443/unsafe_undefined/input.js
issue_1446/undefined_redefined_mangle/input.js
issue_1569/inner_reference/input.js
issue_1609/chained_evaluation_2/input.js
issue_1673/side_effects_else/input.js
issue_1733/function_catch_catch/input.js
issue_1750/case_1/input.js
@ -372,7 +365,6 @@ reduce_vars/defun_var_2/input.js
reduce_vars/escaped_prop_1/input.js
reduce_vars/escaped_prop_2/input.js
reduce_vars/issue_1595_3/input.js
reduce_vars/issue_2916/input.js
reduce_vars/issue_294/input.js
reduce_vars/issue_308/input.js
reduce_vars/issue_432_1/input.js

View File

@ -2,8 +2,7 @@ function f1(x, y) {
return [x + y];
}
function f2(x, y) {
var z = x + y;
return [x, side_effect(), z];
return [x, side_effect(), x + y];
}
function f3(x, y) {
return [[3], [f(x + y), x, y], [g()]];