Skip to content

Commit f584ef7

Browse files
authoredAug 29, 2024··
fix(es/minifier): Iterate object properties in reverse direction while inlining property access (#9507)
**Related issue:** - Closes #9498
1 parent 8c0d79d commit f584ef7

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed
 

‎.changeset/real-bugs-double.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_ecma_transforms_optimization: patch
3+
swc_core: patch
4+
---
5+
6+
fix(es/minifier): Iterate object properties in reverse direction while inlining property access

‎crates/swc_ecma_minifier/tests/exec.rs

+11
Original file line numberDiff line numberDiff line change
@@ -11364,3 +11364,14 @@ fn issue_9499() {
1136411364
fn issue_9356() {
1136511365
run_default_exec_test("console.log((function ({ } = 42) { }).length)");
1136611366
}
11367+
11368+
#[test]
11369+
fn isssue_9498() {
11370+
run_default_exec_test(
11371+
"
11372+
const x = {a: 1};
11373+
const y = {...x, a: 2};
11374+
console.log(y.a);
11375+
",
11376+
)
11377+
}

‎crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1734,7 +1734,7 @@ fn get_key_value(key: &str, props: &mut Vec<PropOrSpread>) -> Option<Box<Expr>>
17341734
return None;
17351735
}
17361736

1737-
for (i, prop) in props.iter_mut().enumerate() {
1737+
for (i, prop) in props.iter_mut().enumerate().rev() {
17381738
let prop = match prop {
17391739
PropOrSpread::Prop(x) => &mut **x,
17401740
PropOrSpread::Spread(_) => unreachable!(),

0 commit comments

Comments
 (0)
Please sign in to comment.