diff --git a/crates/oxc_ecmascript/src/side_effects/may_have_side_effects.rs b/crates/oxc_ecmascript/src/side_effects/may_have_side_effects.rs index 673d43303f976..806c917d58e20 100644 --- a/crates/oxc_ecmascript/src/side_effects/may_have_side_effects.rs +++ b/crates/oxc_ecmascript/src/side_effects/may_have_side_effects.rs @@ -340,6 +340,8 @@ impl MayHaveSideEffects for PropertyKey<'_> { match self { PropertyKey::StaticIdentifier(_) | PropertyKey::PrivateIdentifier(_) => false, match_expression!(PropertyKey) => { + // ToPropertyKey(key) throws an error when ToPrimitive(key) throws an Error + // But we can ignore that by using the assumption. self.to_expression().may_have_side_effects(is_global_reference) } } diff --git a/crates/oxc_minifier/tests/ecmascript/may_have_side_effects.rs b/crates/oxc_minifier/tests/ecmascript/may_have_side_effects.rs index 5e6cd45c0be79..d8b3d4717baf8 100644 --- a/crates/oxc_minifier/tests/ecmascript/may_have_side_effects.rs +++ b/crates/oxc_minifier/tests/ecmascript/may_have_side_effects.rs @@ -560,6 +560,11 @@ fn test_object_expression() { test("({[1]: 1})", false); test("({[1n]: 1})", false); test("({['1']: 1})", false); + // These actually have a side effect, but this treated as side-effect free. + test("({[{ toString() { console.log('sideeffect') } }]: 1})", false); + test("({[{ valueOf() { console.log('sideeffect') } }]: 1})", false); + test("({[{ [s]() { console.log('sideeffect') } }]: 1})", false); // assuming s is Symbol.toPrimitive + test("({[foo]: 1})", false); test("({[foo()]: 1 })", true); test("({a: foo()})", true); test("({...a})", true);