diff --git a/ecmascript/transforms/optimization/Cargo.toml b/ecmascript/transforms/optimization/Cargo.toml index fd9981c90a94..c938a1fc5584 100644 --- a/ecmascript/transforms/optimization/Cargo.toml +++ b/ecmascript/transforms/optimization/Cargo.toml @@ -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] diff --git a/ecmascript/transforms/optimization/src/simplify/branch/tests.rs b/ecmascript/transforms/optimization/src/simplify/branch/tests.rs index 3417a3e83f8b..768b6bea7e12 100644 --- a/ecmascript/transforms/optimization/src/simplify/branch/tests.rs +++ b/ecmascript/transforms/optimization/src/simplify/branch/tests.rs @@ -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()})"); diff --git a/ecmascript/transforms/optimization/src/simplify/expr/mod.rs b/ecmascript/transforms/optimization/src/simplify/expr/mod.rs index de2626a9b8a7..4a19b25fb13c 100644 --- a/ecmascript/transforms/optimization/src/simplify/expr/mod.rs +++ b/ecmascript/transforms/optimization/src/simplify/expr/mod.rs @@ -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 {