Skip to content

Commit

Permalink
fix(es/minifier): Iterate object properties in reverse direction whil…
Browse files Browse the repository at this point in the history
…e inlining property access (#9507)

**Related issue:**

 - Closes #9498
  • Loading branch information
kdy1 committed Aug 29, 2024
1 parent 8c0d79d commit f584ef7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/real-bugs-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_ecma_transforms_optimization: patch
swc_core: patch
---

fix(es/minifier): Iterate object properties in reverse direction while inlining property access
11 changes: 11 additions & 0 deletions crates/swc_ecma_minifier/tests/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11364,3 +11364,14 @@ fn issue_9499() {
fn issue_9356() {
run_default_exec_test("console.log((function ({ } = 42) { }).length)");
}

#[test]
fn isssue_9498() {
run_default_exec_test(
"
const x = {a: 1};
const y = {...x, a: 2};
console.log(y.a);
",
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -1734,7 +1734,7 @@ fn get_key_value(key: &str, props: &mut Vec<PropOrSpread>) -> Option<Box<Expr>>
return None;
}

for (i, prop) in props.iter_mut().enumerate() {
for (i, prop) in props.iter_mut().enumerate().rev() {
let prop = match prop {
PropOrSpread::Prop(x) => &mut **x,
PropOrSpread::Spread(_) => unreachable!(),
Expand Down

0 comments on commit f584ef7

Please sign in to comment.