Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 7, 2025

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

// ✅ 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.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@graphite-app
Copy link
Contributor

graphite-app bot commented Aug 7, 2025

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 hot fixes, skip the queue and merge this PR next

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.

Copilot AI and others added 2 commits August 7, 2025 04:24
Co-authored-by: Brooooooklyn <3468483+Brooooooklyn@users.noreply.github.com>
Co-authored-by: Brooooooklyn <3468483+Brooooooklyn@users.noreply.github.com>
Copilot AI changed the title [WIP] Here is an incomplete task: @oxc-project/oxc/pull/10283 there are code reviews in the comments. Please create a new PR to finish the reset of works in it, and resolve the review comments if needed feat(minifier): safely remove useless unary plus operators in mathematical operations Aug 7, 2025
Copilot AI requested a review from Brooooooklyn August 7, 2025 04:30
Copilot finished work on behalf of Brooooooklyn August 7, 2025 04:30
@Brooooooklyn Brooooooklyn requested a review from sapphi-red August 7, 2025 04:33
@github-actions github-actions bot added A-minifier Area - Minifier C-enhancement Category - New feature or request labels Aug 7, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Aug 7, 2025

CodSpeed Instrumentation Performance Report

Merging #12860 will not alter performance

Comparing copilot/fix-63ee1606-2e5d-4a67-b49a-01a5adbbbfa8 (41b8b6a) with main (9b9249d)1

Summary

✅ 34 untouched benchmarks

Footnotes

  1. No successful run was found on main (ae77ebb) during the generation of this report, so 9b9249d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Copilot AI requested a review from sapphi-red August 7, 2025 04:54
Copilot finished work on behalf of sapphi-red August 7, 2025 04:54
@Brooooooklyn
Copy link
Member

@copilot Why are test cases deleted?

Copy link
Contributor Author

Copilot AI commented Aug 7, 2025

@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:

  • Division/multiplication: +d / 1000, 1000 * +d
  • Bitwise operations: 5 | +b, 7 & +c
  • Complex expressions: 2 - +this._x.call(null, node.data)

I've now restored and expanded these test cases in substitute_alternate_syntax.rs where they belong. The existing implementation actually handles all these cases correctly - the original tests were just too minimal to show the full capability.

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 AI changed the title feat(minifier): safely remove useless unary plus operators in mathematical operations feat(minifier): add comprehensive test coverage for unary plus removal Aug 7, 2025
Copilot finished work on behalf of Brooooooklyn August 7, 2025 05:04
@Brooooooklyn
Copy link
Member

@copilot fix clippy

Co-authored-by: Brooooooklyn <3468483+Brooooooklyn@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 7, 2025

@copilot fix clippy

Fixed the clippy warning by removing duplicate match arms in the binary expression folding logic. The mathematical operators now fall through to the wildcard case since they have identical behavior. All tests pass. (b6bf3d1)

Copilot finished work on behalf of Brooooooklyn August 7, 2025 06:23
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Copilot AI requested a review from sapphi-red August 7, 2025 08:50
Copilot finished work on behalf of sapphi-red August 7, 2025 08:50
@sapphi-red sapphi-red changed the title feat(minifier): add comprehensive test coverage for unary plus removal test(minifier): add comprehensive test coverage for unary plus removal Aug 7, 2025
@github-actions github-actions bot added the C-test Category - Testing. Code is missing test cases, or a PR is adding them label Aug 7, 2025
@sapphi-red sapphi-red marked this pull request as ready for review August 7, 2025 09:36
@sapphi-red sapphi-red merged commit 2c06eda into main Aug 8, 2025
31 checks passed
@sapphi-red sapphi-red deleted the copilot/fix-63ee1606-2e5d-4a67-b49a-01a5adbbbfa8 branch August 8, 2025 01:09
taearls pushed a commit to taearls/oxc that referenced this pull request Aug 12, 2025
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>
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 C-test Category - Testing. Code is missing test cases, or a PR is adding them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants