mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 06:36:08 +03:00
fix(es/minifier): Compress consecutive return statements properly (#9620)
**Description:** Compress consecutive return statements properly. **Related issue:** - Closes https://github.com/swc-project/swc/issues/9619
This commit is contained in:
parent
7b98bb5e93
commit
8263da1766
6
.changeset/famous-keys-shake.md
Normal file
6
.changeset/famous-keys-shake.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
swc_core: patch
|
||||
swc_ecma_minifier: patch
|
||||
---
|
||||
|
||||
fix: compress consecutive return statements properly
|
@ -219,6 +219,16 @@ impl Optimizer<'_> {
|
||||
}
|
||||
},
|
||||
|
||||
(
|
||||
Some(Stmt::Block(BlockStmt { stmts: s1, .. })),
|
||||
Some(Stmt::Block(BlockStmt { stmts: s2, .. })),
|
||||
) if s1.iter().any(|s| matches!(s, Stmt::Return(..)))
|
||||
&& s2.iter().any(|s| matches!(s, Stmt::Return(..))) =>
|
||||
{
|
||||
log_abort!("if_return: [x] Aborting because early return is observed");
|
||||
return;
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,47 @@
|
||||
{
|
||||
"arguments": false,
|
||||
"arrows": false,
|
||||
"booleans": false,
|
||||
"booleans_as_integers": false,
|
||||
"collapse_vars": false,
|
||||
"comparisons": false,
|
||||
"computed_props": false,
|
||||
"conditionals": false,
|
||||
"dead_code": true,
|
||||
"directives": false,
|
||||
"drop_console": false,
|
||||
"drop_debugger": false,
|
||||
"evaluate": false,
|
||||
"expression": false,
|
||||
"hoist_funs": false,
|
||||
"hoist_props": false,
|
||||
"hoist_vars": false,
|
||||
"if_return": true,
|
||||
"join_vars": false,
|
||||
"keep_classnames": false,
|
||||
"keep_fargs": false,
|
||||
"keep_fnames": false,
|
||||
"keep_infinity": false,
|
||||
"loops": false,
|
||||
"negate_iife": false,
|
||||
"properties": false,
|
||||
"reduce_funcs": false,
|
||||
"reduce_vars": false,
|
||||
"side_effects": false,
|
||||
"switches": true,
|
||||
"typeofs": false,
|
||||
"unsafe": false,
|
||||
"unsafe_arrows": false,
|
||||
"unsafe_comps": false,
|
||||
"unsafe_Function": false,
|
||||
"unsafe_math": false,
|
||||
"unsafe_symbols": false,
|
||||
"unsafe_methods": false,
|
||||
"unsafe_proto": false,
|
||||
"unsafe_regexp": false,
|
||||
"unsafe_undefined": false,
|
||||
"unused": true,
|
||||
"const_to_let": false,
|
||||
"pristine_globals": false,
|
||||
"passes": 1
|
||||
}
|
17
crates/swc_ecma_minifier/tests/fixture/issues/9619/input.js
Normal file
17
crates/swc_ecma_minifier/tests/fixture/issues/9619/input.js
Normal file
@ -0,0 +1,17 @@
|
||||
var a = (() => {
|
||||
switch ("production") {
|
||||
case "production":
|
||||
return "expected";
|
||||
default:
|
||||
return "unexpected1";
|
||||
}
|
||||
|
||||
switch ("production") {
|
||||
case "production":
|
||||
return "unexpected2";
|
||||
default:
|
||||
return "unexpected3";
|
||||
}
|
||||
})();
|
||||
|
||||
console.log(a);
|
@ -0,0 +1,2 @@
|
||||
var a = (()=>"expected")();
|
||||
console.log(a);
|
Loading…
Reference in New Issue
Block a user