Skip to content

feat(ecmascript): add property_write_side_effects to MayHaveSideEffectsContext#20217

Merged
graphite-app[bot] merged 1 commit intomainfrom
feat/property-write-side-effects
Mar 12, 2026
Merged

feat(ecmascript): add property_write_side_effects to MayHaveSideEffectsContext#20217
graphite-app[bot] merged 1 commit intomainfrom
feat/property-write-side-effects

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Mar 11, 2026

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

  • Added test_property_write_side_effects_support covering all combinations of write/read side-effect settings
  • Existing tests pass unchanged

Copilot AI review requested due to automatic review settings March 11, 2026 04:28
@github-actions github-actions bot added A-minifier Area - Minifier C-enhancement Category - New feature or request labels Mar 11, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() to MayHaveSideEffectsContext with a conservative default of true.
  • Implement MayHaveSideEffects for AssignmentExpression and UpdateExpression, 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.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 11, 2026

Merging this PR will not alter performance

✅ 53 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing feat/property-write-side-effects (cb8b1f6) with main (36e7d29)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Member Author

Dunqing commented Mar 11, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of 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.

@Dunqing Dunqing changed the title feat(ecmascript): add property_write_side_effects to MayHaveSideEffectsContext feat(ecmascript): add property_write_side_effects to MayHaveSideEffectsContext Mar 11, 2026
@Dunqing Dunqing requested review from Boshen and sapphi-red March 12, 2026 05:36
@Dunqing Dunqing force-pushed the feat/property-write-side-effects branch from 8172e82 to 7857402 Compare March 12, 2026 05:57
@Dunqing Dunqing force-pushed the feat/property-write-side-effects branch from 7857402 to cb8b1f6 Compare March 12, 2026 06:57
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Mar 12, 2026
Copy link
Member

Boshen commented Mar 12, 2026

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
@graphite-app graphite-app bot force-pushed the feat/property-write-side-effects branch from cb8b1f6 to 139ab68 Compare March 12, 2026 07:25
@graphite-app graphite-app bot merged commit 139ab68 into main Mar 12, 2026
21 checks passed
@graphite-app graphite-app bot deleted the feat/property-write-side-effects branch March 12, 2026 07:36
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 12, 2026
graphite-app bot pushed a commit that referenced this pull request Mar 12, 2026
#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)
Boshen added a commit that referenced this pull request Mar 14, 2026
### 🚀 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants