Skip to content

Commit 985977b

Browse files
authored
fix(es/minifier): Do not inline into the exact LHS (#9777)
**Related issue:** - Closes #9739
1 parent f54ec2c commit 985977b

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

.changeset/big-mails-kneel.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_core: patch
3+
swc_ecma_minifier: patch
4+
---
5+
6+
fix(es/minifier): Do not inline into the exact LHS

crates/swc_ecma_minifier/src/compress/optimize/inline.rs

+4
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,10 @@ impl Optimizer<'_> {
789789

790790
/// Actually inlines variables.
791791
pub(super) fn inline(&mut self, e: &mut Expr) {
792+
if self.ctx.is_exact_lhs_of_assign {
793+
return;
794+
}
795+
792796
match e {
793797
Expr::Member(me) => {
794798
if let MemberProp::Computed(prop) = &mut me.prop {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"arguments": false,
3+
"arrows": true,
4+
"booleans": true,
5+
"booleans_as_integers": false,
6+
"collapse_vars": true,
7+
"comparisons": true,
8+
"computed_props": true,
9+
"conditionals": true,
10+
"dead_code": true,
11+
"directives": true,
12+
"drop_console": false,
13+
"drop_debugger": true,
14+
"evaluate": true,
15+
"expression": false,
16+
"hoist_funs": false,
17+
"hoist_props": true,
18+
"hoist_vars": false,
19+
"if_return": true,
20+
"join_vars": true,
21+
"keep_classnames": false,
22+
"keep_fargs": true,
23+
"keep_fnames": false,
24+
"keep_infinity": false,
25+
"loops": true,
26+
"negate_iife": true,
27+
"properties": true,
28+
"reduce_funcs": false,
29+
"reduce_vars": false,
30+
"side_effects": true,
31+
"switches": true,
32+
"typeofs": true,
33+
"unsafe": false,
34+
"unsafe_arrows": false,
35+
"unsafe_comps": false,
36+
"unsafe_Function": false,
37+
"unsafe_math": false,
38+
"unsafe_symbols": false,
39+
"unsafe_methods": false,
40+
"unsafe_proto": false,
41+
"unsafe_regexp": false,
42+
"unsafe_undefined": false,
43+
"unused": true,
44+
"const_to_let": true,
45+
"pristine_globals": true
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const arr = ['a', 'b'];
2+
[arr[0], arr[1]] = [arr[1], arr[0]];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const arr = [
2+
'a',
3+
'b'
4+
];
5+
[arr[0], arr[1]] = [
6+
'b',
7+
'a'
8+
];

0 commit comments

Comments
 (0)