-
-
Notifications
You must be signed in to change notification settings - Fork 720
test(minifier): add comprehensive test coverage for unary plus removal #12860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(minifier): add comprehensive test coverage for unary plus removal #12860
Conversation
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. |
Co-authored-by: Brooooooklyn <3468483+Brooooooklyn@users.noreply.github.com>
Co-authored-by: Brooooooklyn <3468483+Brooooooklyn@users.noreply.github.com>
CodSpeed Instrumentation Performance ReportMerging #12860 will not alter performanceComparing Summary
Footnotes |
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
|
@copilot Why are test cases deleted? |
You're absolutely right to question this. I mistakenly deleted valuable test cases that provided additional coverage beyond the basic tests. While I correctly removed duplicate implementation code, the test cases I deleted were more comprehensive than the existing ones and covered important scenarios like:
I've now restored and expanded these test cases in Commit: d1a47f2 |
Add comprehensive test coverage for unary plus removal including: - Division and multiplication operations - Bitwise operations (|, &, ^) - Complex expressions with method calls - Additional safety test cases The existing substitute_alternate_syntax.rs implementation handles all these cases correctly, but the test coverage was too minimal to demonstrate the full capability. Co-authored-by: Brooooooklyn <3468483+Brooooooklyn@users.noreply.github.com>
|
@copilot fix clippy |
Co-authored-by: Brooooooklyn <3468483+Brooooooklyn@users.noreply.github.com>
crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs
Outdated
Show resolved
Hide resolved
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs
Outdated
Show resolved
Hide resolved
oxc-project#12860) This PR adds comprehensive test coverage for the existing unary plus removal functionality in `substitute_alternate_syntax.rs`, which safely removes redundant unary plus operators (`+`) in mathematical operations while avoiding BigInt compatibility issues. ## Problem The existing implementation correctly handles safe removal of unary plus operators, but the test coverage was minimal and didn't demonstrate the full capability of the feature. This made it unclear what scenarios were supported. ## Solution Added comprehensive test cases that demonstrate the implementation correctly handles: - **Mathematical operations**: Division, multiplication, bitwise operations (`|`, `&`, `^`) - **Complex expressions**: Method calls, member access, nested expressions - **Safety checks**: Properly preserves unary plus when operand types are unknown to avoid BigInt runtime errors ## Examples ```javascript // ✅ Safe optimizations (other operand is number literal) +d / 1000 → d / 1000 1000 * +d → 1000 * d 5 | +b → 5 | b 2 - +x.call() → 2 - x.call() // ✅ Correctly preserved (unknown operand types) a | +b → a | +b (unchanged) +a * b → +a * b (unchanged) ``` The expanded test suite confirms the implementation works correctly across all supported mathematical operations while maintaining BigInt safety. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/oxc-project/oxc/issues/new?title=✨Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Brooooooklyn <3468483+Brooooooklyn@users.noreply.github.com> Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This PR adds comprehensive test coverage for the existing unary plus removal functionality in
substitute_alternate_syntax.rs, which safely removes redundant unary plus operators (+) in mathematical operations while avoiding BigInt compatibility issues.Problem
The existing implementation correctly handles safe removal of unary plus operators, but the test coverage was minimal and didn't demonstrate the full capability of the feature. This made it unclear what scenarios were supported.
Solution
Added comprehensive test cases that demonstrate the implementation correctly handles:
|,&,^)Examples
The expanded test suite confirms the implementation works correctly across all supported mathematical operations while maintaining BigInt safety.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.