Skip to content

Commit

Permalink
fix(es/transforms/optimization): Preserve missing object members (#1567)
Browse files Browse the repository at this point in the history
swc_ecma_transforms_optimization:
 - Don't replace missing object members with undefined
  • Loading branch information
mischnic authored Apr 12, 2021
1 parent 14edb69 commit e43de77
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ecmascript/transforms/optimization/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecma_transforms_optimization"
repository = "https://github.com/swc-project/swc.git"
version = "0.15.2"
version = "0.15.3"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,7 @@ fn test_object_literal() {
test("({a:1})", "");
test("({a:foo()})", "foo()");
test("({'a':foo()})", "foo()");
test("({}).foo", "({}).foo");
// Object-spread may trigger getters.
test_same("({...a})");
test_same("({...foo()})");
Expand Down
12 changes: 7 additions & 5 deletions ecmascript/transforms/optimization/src/simplify/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,13 @@ impl SimplifyExpr {
once(Box::new(Expr::Object(ObjectLit { props, span }))),
)
}
None => preserve_effects(
span,
*undefined(span),
once(Box::new(Expr::Object(ObjectLit { props, span }))),
),
None => Expr::Member(MemberExpr {
obj: ExprOrSuper::Expr(Box::new(Expr::Object(ObjectLit {
props,
span,
}))),
..e
}),
}
}
_ => Expr::Member(MemberExpr {
Expand Down

0 comments on commit e43de77

Please sign in to comment.