fix(es/minifier): Remove the last break in the last BlockStmt (#4413)

This commit is contained in:
Austaras 2022-04-24 11:26:49 +08:00 committed by GitHub
parent 3e2931e878
commit 83244add33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 221 additions and 6 deletions

View File

@ -439,12 +439,14 @@ where
} }
fn remove_last_break(stmt: &mut Vec<Stmt>) -> bool { fn remove_last_break(stmt: &mut Vec<Stmt>) -> bool {
if let Some(Stmt::Break(BreakStmt { label: None, .. })) = stmt.last() { match stmt.last_mut() {
Some(Stmt::Break(BreakStmt { label: None, .. })) => {
report_change!("switches: Removing `break` at the end"); report_change!("switches: Removing `break` at the end");
stmt.pop(); stmt.pop();
true true
} else { }
false Some(Stmt::Block(BlockStmt { stmts, .. })) => remove_last_break(stmts),
_ => false,
} }
} }

View File

@ -0,0 +1,196 @@
TestSnapshot {
vars: [
(
(
Atom('ENUM_VALUE' type=dynamic),
#1,
),
VarUsageInfo {
inline_prevented: false,
ref_count: 1,
cond_init: false,
declared: false,
declared_count: 0,
declared_as_fn_param: false,
declared_as_fn_expr: false,
assign_count: 0,
mutation_by_call_count: 0,
usage_count: 1,
reassigned_with_assignment: false,
reassigned_with_var_decl: false,
mutated: false,
has_property_access: false,
has_property_mutation: false,
accessed_props: {},
exported: false,
used_above_decl: true,
is_fn_local: true,
used_by_nested_fn: true,
executed_multiple_time: false,
used_in_cond: false,
var_kind: None,
var_initialized: false,
declared_as_catch_param: false,
no_side_effect_for_member_access: false,
used_as_callee: false,
used_as_arg: false,
pure_fn: false,
infects: [],
},
),
(
(
Atom('arg' type=inline),
#2,
),
VarUsageInfo {
inline_prevented: false,
ref_count: 2,
cond_init: false,
declared: true,
declared_count: 1,
declared_as_fn_param: true,
declared_as_fn_expr: false,
assign_count: 0,
mutation_by_call_count: 0,
usage_count: 2,
reassigned_with_assignment: false,
reassigned_with_var_decl: false,
mutated: false,
has_property_access: false,
has_property_mutation: false,
accessed_props: {},
exported: false,
used_above_decl: false,
is_fn_local: true,
used_by_nested_fn: true,
executed_multiple_time: false,
used_in_cond: true,
var_kind: None,
var_initialized: false,
declared_as_catch_param: false,
no_side_effect_for_member_access: false,
used_as_callee: false,
used_as_arg: false,
pure_fn: false,
infects: [],
},
),
(
(
Atom('call' type=static),
#1,
),
VarUsageInfo {
inline_prevented: false,
ref_count: 1,
cond_init: false,
declared: false,
declared_count: 0,
declared_as_fn_param: false,
declared_as_fn_expr: false,
assign_count: 0,
mutation_by_call_count: 0,
usage_count: 1,
reassigned_with_assignment: false,
reassigned_with_var_decl: false,
mutated: false,
has_property_access: false,
has_property_mutation: false,
accessed_props: {},
exported: false,
used_above_decl: true,
is_fn_local: true,
used_by_nested_fn: true,
executed_multiple_time: false,
used_in_cond: true,
var_kind: None,
var_initialized: false,
declared_as_catch_param: false,
no_side_effect_for_member_access: false,
used_as_callee: true,
used_as_arg: false,
pure_fn: false,
infects: [],
},
),
(
(
Atom('data' type=inline),
#3,
),
VarUsageInfo {
inline_prevented: false,
ref_count: 1,
cond_init: true,
declared: true,
declared_count: 1,
declared_as_fn_param: false,
declared_as_fn_expr: false,
assign_count: 0,
mutation_by_call_count: 1,
usage_count: 1,
reassigned_with_assignment: false,
reassigned_with_var_decl: false,
mutated: true,
has_property_access: false,
has_property_mutation: false,
accessed_props: {},
exported: false,
used_above_decl: false,
is_fn_local: true,
used_by_nested_fn: true,
executed_multiple_time: false,
used_in_cond: true,
var_kind: Some(
"const",
),
var_initialized: true,
declared_as_catch_param: false,
no_side_effect_for_member_access: false,
used_as_callee: false,
used_as_arg: true,
pure_fn: false,
infects: [],
},
),
(
(
Atom('foo' type=inline),
#1,
),
VarUsageInfo {
inline_prevented: true,
ref_count: 0,
cond_init: false,
declared: true,
declared_count: 1,
declared_as_fn_param: false,
declared_as_fn_expr: false,
assign_count: 0,
mutation_by_call_count: 0,
usage_count: 0,
reassigned_with_assignment: false,
reassigned_with_var_decl: false,
mutated: false,
has_property_access: false,
has_property_mutation: false,
accessed_props: {},
exported: false,
used_above_decl: false,
is_fn_local: true,
used_by_nested_fn: false,
executed_multiple_time: false,
used_in_cond: false,
var_kind: None,
var_initialized: true,
declared_as_catch_param: false,
no_side_effect_for_member_access: false,
used_as_callee: false,
used_as_arg: false,
pure_fn: false,
infects: [],
},
),
],
}

View File

@ -0,0 +1,11 @@
export function foo(arg) {
switch (arg) {
case ENUM_VALUE: {
const { data } = arg;
call(data);
break;
}
default:
break;
}
}

View File

@ -0,0 +1,6 @@
export function foo(arg) {
if (arg === ENUM_VALUE) {
const { data } = arg;
call(data);
}
}