mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
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) <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
2 files changed
+15
-4
No files matched your search
@@ -650,10 +650,16 @@ impl<'a> MayHaveSideEffects<'a> for ObjectPropertyKind<'a> {
|
||||
} else {
|
||||
match &e.argument {
|
||||
Expression::ArrayExpression(arr) => arr.may_have_side_effects(ctx),
|
||||
Expression::ObjectExpression(obj) => obj
|
||||
.properties
|
||||
.iter()
|
||||
.any(|property| property.may_have_side_effects(ctx)),
|
||||
Expression::ObjectExpression(obj) => {
|
||||
obj.properties.iter().any(|property| match property {
|
||||
ObjectPropertyKind::ObjectProperty(p) => {
|
||||
p.kind == PropertyKind::Get || p.may_have_side_effects(ctx)
|
||||
}
|
||||
ObjectPropertyKind::SpreadProperty(e) => {
|
||||
e.argument.may_have_side_effects(ctx)
|
||||
}
|
||||
})
|
||||
}
|
||||
Expression::StringLiteral(_) => false,
|
||||
Expression::TemplateLiteral(t) => t.may_have_side_effects(ctx),
|
||||
_ => true,
|
||||
|
||||
@@ -717,6 +717,11 @@ fn test_object_expression() {
|
||||
test("({...{a: 1}})", false);
|
||||
test("({...{a: foo()}})", true);
|
||||
test("({...{[foo()]: 1}})", true);
|
||||
// Getters are invoked when spreading
|
||||
test("({...{get a() {}}})", true);
|
||||
test("({...{get a() { return 1 }}})", true);
|
||||
// Setters are NOT invoked when spreading
|
||||
test("({...{set a(v) {}}})", false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user