fix(ecmascript): enhance side-effect detection for classes, TypedArrays, computed members, and spread#20213
Conversation
There was a problem hiding this comment.
Pull request overview
Improves may_have_side_effects accuracy in oxc_ecmascript (used by the minifier/DCE) for additional ECMAScript/TypeScript constructs and expands test coverage to prevent regressions.
Changes:
- Refines side-effect detection for computed member expressions and object spread when
property_read_side_effects == None. - Extends class-element handling (method parameter decorators, accessor property initializers).
- Treats TypedArray constructors as pure (and adds minifier tests for the new cases).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/oxc_minifier/tests/ecmascript/may_have_side_effects.rs | Adds regression tests for computed members, object spread, TS parameter decorators, accessor initializers, and TypedArray constructors. |
| crates/oxc_ecmascript/src/side_effects/expressions.rs | Updates side-effect logic for object spread/computed members/class elements; expands pure constructors; introduces AssignmentExpression/UpdateExpression handling. |
| crates/oxc_ecmascript/src/side_effects/context.rs | Adds a property_write_side_effects() hook to the side-effects context. |
1fe424a to
f0ccc25
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. |
Merging this PR will not alter performance
Comparing Footnotes
|
8f68e8b to
411b61a
Compare
f0ccc25 to
3599797
Compare
3089aca to
cacff2f
Compare
3599797 to
e39ffe3
Compare
cacff2f to
4c397f0
Compare
01cb8fd to
1a433a8
Compare
1a433a8 to
988d663
Compare
4c397f0 to
4d3b18e
Compare
988d663 to
1b9c059
Compare
4d3b18e to
4d6a096
Compare
Merge activity
|
4d6a096 to
d12655d
Compare
1b9c059 to
5b8ac85
Compare
…ys, computed members, and spread (#20213) ## Summary Part of #19673 Several side-effect detection improvements: - **Computed member expressions**: When `property_read_side_effects` is `None`, non-literal keys (e.g. `obj[identRef]`) now check the key expression and object for their own side effects instead of always returning `true` - **ObjectExpression spread**: When `property_read_side_effects` is `None`, `{...expr}` delegates to the argument's own side effects - **Class MethodDefinition**: Now checks for parameter decorators (TypeScript `@foo` on params) - **Class AccessorProperty**: Now checks accessor property values for side effects - **TypedArray constructors**: Added `Int8Array`, `Uint8Array`, `Uint8ClampedArray`, `Int16Array`, `Uint16Array`, `Int32Array`, `Uint32Array`, `Float32Array`, `Float64Array`, `BigInt64Array`, `BigUint64Array` to pure constructors (`DataView` excluded as it requires an `ArrayBuffer` argument) ## Test plan - [x] Added tests for computed member non-literal keys with `property_read_side_effects` - [x] Added tests for ObjectExpression spread with `property_read_side_effects` - [x] Added tests for class method parameter decorators - [x] Added tests for class accessor property values - [x] Added tests for TypedArray constructors - [x] All existing tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code)
c4c894c to
e7163b6
Compare
0a97c72 to
ade14d4
Compare
### 🚀 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>

Summary
Part of #19673
Several side-effect detection improvements:
property_read_side_effectsisNone, non-literal keys (e.g.obj[identRef]) now check the key expression and object for their own side effects instead of always returningtrueproperty_read_side_effectsisNone,{...expr}delegates to the argument's own side effects@fooon params)Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Arrayto pure constructors (DataViewexcluded as it requires anArrayBufferargument)Test plan
property_read_side_effectsproperty_read_side_effects🤖 Generated with Claude Code