feat: implement side-effect analysis relaxations to match rolldown behavior #12976
+400
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements four key side-effect analysis relaxations in oxc to improve tree-shaking capabilities and match rolldown's behavior for better compatibility.
Background
Currently, oxc's side-effect analysis is overly conservative in several areas, preventing the removal of code that could safely be eliminated. This leads to larger bundle sizes compared to rolldown and other bundlers that have more sophisticated analysis.
Changes
1. Side-effect-free global constructors
Global constructors are now considered side-effect-free in specific argument shapes:
The constructors must be global references, and arguments are still evaluated for side effects.
2. Improved static class block analysis
Static class blocks now examine their content instead of assuming all non-empty blocks have side effects:
3. Known side-effect-free global member reads
Specific global property accesses are now whitelisted as side-effect-free:
4. Symbol.iterator computed property keys
Computed property keys using
Symbol.iterator
are now side-effect-free:5. Expanded global identifier whitelist
Added
String
andProxy
to the list of side-effect-free global identifier reads, joiningNaN
,Infinity
, andundefined
.Testing
Added comprehensive test coverage for all new functionality:
All existing tests continue to pass, ensuring no regressions.
Impact
These changes will result in:
The implementation maintains all existing configurability options and respects user preferences for side-effect analysis strictness.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.