feat(ecmascript): add property_write_side_effects to MayHaveSideEffectsContext#20217
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the ECMAScript side-effect analysis to support a property_write_side_effects() flag on MayHaveSideEffectsContext, enabling more precise classification of assignment/update expressions for treeshaking/minification scenarios.
Changes:
- Add
property_write_side_effects()toMayHaveSideEffectsContextwith a conservative default oftrue. - Implement
MayHaveSideEffectsforAssignmentExpressionandUpdateExpression, allowing member-property writes to be treated as side-effect-free when configured. - Add tests covering combinations of property read/write side-effect settings.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/oxc_ecmascript/src/side_effects/context.rs | Adds the new context flag API with a default conservative behavior. |
| crates/oxc_ecmascript/src/side_effects/expressions.rs | Routes assignment/update expressions through dedicated side-effect logic and implements the new behavior. |
| crates/oxc_minifier/tests/ecmascript/may_have_side_effects.rs | Adds test coverage for the new property-write side effects option and its interaction with property-read settings. |
Merging this PR will not alter performance
Comparing Footnotes
|
dd1d6c7 to
8172e82
Compare
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
property_write_side_effects to MayHaveSideEffectsContext
8172e82 to
7857402
Compare
7857402 to
cb8b1f6
Compare
Merge activity
|
…fectsContext` (#20217) Part of #19673 ## Summary - Add `property_write_side_effects()` to `MayHaveSideEffectsContext` trait with default `true` (conservative) - Implement `MayHaveSideEffects` for `AssignmentExpression` and `UpdateExpression` (previously fell through to `_ => true`) - When `property_write_side_effects` is `false`, member expression writes are side-effect-free - Compound assignments (`+=`) and updates (`++`) still respect `property_read_side_effects` for their implicit reads - Reference: https://rolldown.rs/reference/InputOptions.treeshake#propertywritesideeffects ## Test plan - [x] Added `test_property_write_side_effects_support` covering all combinations of write/read side-effect settings - [x] Existing tests pass unchanged
cb8b1f6 to
139ab68
Compare
#20212) ## Summary close: #13067 Part of #19673 Depends on #20217. Port known-globals lists from Rolldown to Oxc's side-effect detection: - **Global identifiers** (Math, Array, console, DOM classes, etc.) are now considered side-effect-free to access via `is_known_global_identifier`, matching Rolldown's `GLOBAL_IDENT` set - **Property reads** like `Math.PI`, `console.log`, `Object.keys` are considered side-effect-free via `is_known_global_property` - **3-level chains** like `Object.prototype.hasOwnProperty` are supported via `is_known_global_property_deep` ## Test plan - [x] Added tests for known global identifiers (Math, Array, Object, console, etc.) - [x] Added tests for known global property reads (Math.PI, Object.keys, etc.) - [x] Added tests for 3-level chains (Object.prototype.hasOwnProperty, etc.) - [x] Existing minifier test expectations updated for improved side-effect detection - [x] All existing tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code)
### 🚀 Features - e7163b6 ecmascript: Add known-globals to side-effect-free property reads (#20212) (Dunqing) - 139ab68 ecmascript: Add `property_write_side_effects` to `MayHaveSideEffectsContext` (#20217) (Dunqing) ### 🐛 Bug Fixes - 78c264a parser: Fix conditional expressions with arrow-function alternates in TS (#20356) (camc314) - 5c97b14 minifier: Recognize object spread of object literals as side-effect-free (#20299) (Boshen) - 1ff5c1d transformer/typescript: Rewrite extensions in dynamic `import()` expressions (#20121) (Sverre Johansen) - 1c07b3b diagnostics: Handle `WouldBlock` in stdout writes to prevent panic (#20295) (Boshen) - ade14d4 ecmascript: Enhance side-effect detection for classes, TypedArrays, computed members, and spread (#20213) (Dunqing) ### ⚡ Performance - 5474d0a semantic: V8-style walk-up reference resolution (#20292) (Boshen) ### 📚 Documentation - e4aa5b5 parser/napi, linter/plugins: Add JSDoc comments to raw transfer constants (#20286) (overlookmotel) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>

Part of #19673
Summary
property_write_side_effects()toMayHaveSideEffectsContexttrait with defaulttrue(conservative)MayHaveSideEffectsforAssignmentExpressionandUpdateExpression(previously fell through to_ => true)property_write_side_effectsisfalse, member expression writes are side-effect-free+=) and updates (++) still respectproperty_read_side_effectsfor their implicit readsTest plan
test_property_write_side_effects_supportcovering all combinations of write/read side-effect settings