Skip to content

Commit e62524d

Browse files
Boshenclaudeautofix-ci[bot]
authored
fix(minifier): treat object spread of getters as having side effects (#20380)
## Summary - Object spread (`...{ get prop() {} }`) invokes getters at runtime, so it has side effects - The previous code only checked key/value AST nodes and missed the getter invocation - Setters are **not** invoked by spread, so they remain side-effect-free - Fixes the Rolldown test `rollup@function@object-spread-side-effect` 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 618a598 commit e62524d

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

crates/oxc_ecmascript/src/side_effects/expressions.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,16 @@ impl<'a> MayHaveSideEffects<'a> for ObjectPropertyKind<'a> {
650650
} else {
651651
match &e.argument {
652652
Expression::ArrayExpression(arr) => arr.may_have_side_effects(ctx),
653-
Expression::ObjectExpression(obj) => obj
654-
.properties
655-
.iter()
656-
.any(|property| property.may_have_side_effects(ctx)),
653+
Expression::ObjectExpression(obj) => {
654+
obj.properties.iter().any(|property| match property {
655+
ObjectPropertyKind::ObjectProperty(p) => {
656+
p.kind == PropertyKind::Get || p.may_have_side_effects(ctx)
657+
}
658+
ObjectPropertyKind::SpreadProperty(e) => {
659+
e.argument.may_have_side_effects(ctx)
660+
}
661+
})
662+
}
657663
Expression::StringLiteral(_) => false,
658664
Expression::TemplateLiteral(t) => t.may_have_side_effects(ctx),
659665
_ => true,

crates/oxc_minifier/tests/ecmascript/may_have_side_effects.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,11 @@ fn test_object_expression() {
717717
test("({...{a: 1}})", false);
718718
test("({...{a: foo()}})", true);
719719
test("({...{[foo()]: 1}})", true);
720+
// Getters are invoked when spreading
721+
test("({...{get a() {}}})", true);
722+
test("({...{get a() { return 1 }}})", true);
723+
// Setters are NOT invoked when spreading
724+
test("({...{set a(v) {}}})", false);
720725
}
721726

722727
#[test]

0 commit comments

Comments
 (0)