Skip to content

Commit e554381

Browse files
authored
fix(es/minifier): Inline object of member if prop is an ident (#10548)
**Description:** Currently, if there's an object ident in a member with a computed ident prop, it won't be inlined. So add this case. **Related issue:** - Closes #10532
1 parent b101a87 commit e554381

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

.changeset/light-ties-argue.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_ecma_minifier: patch
3+
swc_core: patch
4+
---
5+
6+
fix(es/minifier): inline object of member if prop is an ident

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ impl VisitMut for Finalizer<'_> {
351351
let sym = match &e.prop {
352352
MemberProp::Ident(i) => &i.sym,
353353
MemberProp::Computed(e) => match &*e.expr {
354+
Expr::Ident(ident) => &ident.sym,
354355
Expr::Lit(Lit::Str(s)) => &s.value,
355356
_ => return,
356357
},
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(function () {
2+
function WL(t) {
3+
var n = (console.log(), t);
4+
Object.keys(n).forEach(function (t) {
5+
console.log(n);
6+
console.log(t);
7+
console.log(n[t]);
8+
});
9+
}
10+
try {
11+
t = { a: 1 };
12+
WL(t);
13+
} catch {}
14+
})();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
try {
2+
var t1;
3+
t1 = t = {
4+
a: 1
5+
}, console.log(), Object.keys(t1).forEach(function(t2) {
6+
console.log(t1), console.log(t2), console.log(t1[t2]);
7+
});
8+
} catch {}

0 commit comments

Comments
 (0)