Skip to content

Commit

Permalink
fix(es/minifier): Do not inline into the exact LHS (#9777)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #9739
  • Loading branch information
kdy1 authored Dec 2, 2024
1 parent f54ec2c commit 985977b
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/big-mails-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_core: patch
swc_ecma_minifier: patch
---

fix(es/minifier): Do not inline into the exact LHS
4 changes: 4 additions & 0 deletions crates/swc_ecma_minifier/src/compress/optimize/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,10 @@ impl Optimizer<'_> {

/// Actually inlines variables.
pub(super) fn inline(&mut self, e: &mut Expr) {
if self.ctx.is_exact_lhs_of_assign {
return;
}

match e {
Expr::Member(me) => {
if let MemberProp::Computed(prop) = &mut me.prop {
Expand Down
46 changes: 46 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/9739/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"arguments": false,
"arrows": true,
"booleans": true,
"booleans_as_integers": false,
"collapse_vars": true,
"comparisons": true,
"computed_props": true,
"conditionals": true,
"dead_code": true,
"directives": true,
"drop_console": false,
"drop_debugger": true,
"evaluate": true,
"expression": false,
"hoist_funs": false,
"hoist_props": true,
"hoist_vars": false,
"if_return": true,
"join_vars": true,
"keep_classnames": false,
"keep_fargs": true,
"keep_fnames": false,
"keep_infinity": false,
"loops": true,
"negate_iife": true,
"properties": true,
"reduce_funcs": false,
"reduce_vars": false,
"side_effects": true,
"switches": true,
"typeofs": true,
"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": true,
"pristine_globals": true
}
2 changes: 2 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/9739/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const arr = ['a', 'b'];
[arr[0], arr[1]] = [arr[1], arr[0]];
8 changes: 8 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/9739/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const arr = [
'a',
'b'
];
[arr[0], arr[1]] = [
'b',
'a'
];

0 comments on commit 985977b

Please sign in to comment.