Skip to content

refactor(ecmascript): align side-effect analysis with spec coercions#19308

Merged
graphite-app[bot] merged 1 commit intomainfrom
boshen/spec-align-side-effects
Feb 12, 2026
Merged

refactor(ecmascript): align side-effect analysis with spec coercions#19308
graphite-app[bot] merged 1 commit intomainfrom
boshen/spec-align-side-effects

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Feb 12, 2026

Summary

  • align side-effect detection for conversion-heavy global calls with spec behavior
  • add explicit handling for PrivateInExpression throw behavior on non-object RHS
  • treat import.meta.url property reads as side-effect free
  • expand minifier may-have-side-effects tests for String/Number/Boolean/BigInt/Symbol coercion cases

Testing

  • cargo test -p oxc_minifier may_have_side_effects -- --nocapture
  • cargo test -p oxc_ecmascript

AI Usage

  • Drafted with AI assistance (Codex) and reviewed/tested by the author.

@github-actions github-actions bot added A-minifier Area - Minifier C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Feb 12, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 12, 2026

Merging this PR will not alter performance

✅ 47 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing boshen/spec-align-side-effects (8402de4) with main (aa1e1a8)

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.

@Boshen Boshen marked this pull request as ready for review February 12, 2026 15:23
Copilot AI review requested due to automatic review settings February 12, 2026 15:23
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Feb 12, 2026
Copy link
Member Author

Boshen commented Feb 12, 2026

Merge activity

…19308)

## Summary
- align side-effect detection for conversion-heavy global calls with spec behavior
- add explicit handling for `PrivateInExpression` throw behavior on non-object RHS
- treat `import.meta.url` property reads as side-effect free
- expand minifier may-have-side-effects tests for String/Number/Boolean/BigInt/Symbol coercion cases

## Testing
- cargo test -p oxc_minifier may_have_side_effects -- --nocapture
- cargo test -p oxc_ecmascript

## AI Usage
- Drafted with AI assistance (Codex) and reviewed/tested by the author.
@graphite-app graphite-app bot force-pushed the boshen/spec-align-side-effects branch from 8402de4 to 4538098 Compare February 12, 2026 15:25
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 refines side-effect analysis for ECMAScript type coercion functions (String, Number, BigInt, Symbol) to align with spec behavior, adds explicit handling for PrivateInExpression throw semantics, and treats import.meta.url as side-effect-free. The changes improve minification accuracy by better detecting when these global functions can safely be eliminated.

Changes:

  • Replaced generic "pure call" handling for String/Number/BigInt/Symbol with spec-aligned analysis that checks ToPrimitive behavior to detect user code execution via valueOf/toString
  • Added PrivateInExpression handling that throws TypeError on non-object RHS
  • Marked import.meta.url property reads as side-effect-free (with a critical bug - see comments)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
crates/oxc_ecmascript/src/side_effects/expressions.rs Implements refined side-effect analysis for type coercion functions, PrivateInExpression, and import.meta.url
crates/oxc_minifier/tests/ecmascript/may_have_side_effects.rs Adds comprehensive test coverage for String/Number/BigInt/Symbol coercion edge cases and PrivateInExpression
crates/oxc_minifier/tests/peephole/substitute_alternate_syntax.rs Updates BigInt(1) test to expect removal (no side effects)
crates/oxc_minifier/tests/peephole/obscure_edge_cases.rs Updates import.meta.url test to expect removal (no side effects)

|| object.value_type(ctx).is_string())
}
// `import.meta.url` is spec-defined and side-effect free.
"url" if matches!(object.without_parentheses(), Expression::MetaProperty(_)) => false,
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

The check for side-effect-free property access should specifically verify that the MetaProperty is import.meta, not just any MetaProperty. Currently, this would also incorrectly treat new.target.url as side-effect-free. Consider checking if the MetaProperty has meta.name == "import" and property.name == "meta" before treating the url property access as side-effect-free. For example: if let Expression::MetaProperty(meta_prop) = object.without_parentheses() and meta_prop.meta.name == "import" and meta_prop.property.name == "meta".

Suggested change
"url" if matches!(object.without_parentheses(), Expression::MetaProperty(_)) => false,
"url" => {
if let Expression::MetaProperty(meta_prop) = object.without_parentheses() {
if meta_prop.meta.name == "import" && meta_prop.property.name == "meta" {
return false;
}
}
true
}

Copilot uses AI. Check for mistakes.
@graphite-app graphite-app bot merged commit 4538098 into main Feb 12, 2026
21 checks passed
@graphite-app graphite-app bot deleted the boshen/spec-align-side-effects branch February 12, 2026 15:32
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants