Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_minifier/tests/ecmascript/may_have_side_effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading