Skip to content
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

feat(es/minifier): Support unary negate in cast_to_number #9642

Merged
merged 2 commits into from
Oct 14, 2024

Conversation

levi-nz
Copy link
Contributor

@levi-nz levi-nz commented Oct 14, 2024

Description:
Adds support for - in cast_to_number. Before it only worked if arg is Infinity. Now it uses a recursive call on arg so it works for expressions like -5, -[] etc.

This change is important because negative number literals (e.g. -5) are a UnaryExpr with op=- & arg=5, unless you apply expr_simplifier pass or something else that uses it.

BREAKING CHANGE:

Related issue (if exists):

@levi-nz levi-nz requested a review from a team as a code owner October 14, 2024 12:56
Copy link

changeset-bot bot commented Oct 14, 2024

🦋 Changeset detected

Latest commit: 9e41997

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CPunisher
Copy link
Member

Could you please add some tests?

@levi-nz
Copy link
Contributor Author

levi-nz commented Oct 14, 2024

Could you please add some tests?

There doesn't seem to be any tests for cast_to_number in this file, or anywhere else that I can see. So I don't think tests are required. Also this change is simply a recursive call.

CPunisher
CPunisher previously approved these changes Oct 14, 2024
Copy link

codspeed-hq bot commented Oct 14, 2024

CodSpeed Performance Report

Merging #9642 will improve performances by 3.35%

Comparing levi-nz:negative-number-casting (9e41997) with main (085bc19)

Summary

⚡ 1 improvements
✅ 193 untouched benchmarks

Benchmarks breakdown

Benchmark main levi-nz:negative-number-casting Change
es/oxc/benches/assets/UserSettings.tsx/sourceMap=true/reactDev=false 1.5 ms 1.5 ms +3.35%

@kdy1 kdy1 self-assigned this Oct 14, 2024
@kdy1 kdy1 added this to the Planned milestone Oct 14, 2024
@kdy1 kdy1 requested a review from a team as a code owner October 14, 2024 23:00
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

Thank you!

@kdy1 kdy1 merged commit 88a2186 into swc-project:main Oct 14, 2024
23 of 24 checks passed
@kdy1 kdy1 modified the milestones: Planned, v1.7.36 Oct 15, 2024
@swc-project swc-project locked as resolved and limited conversation to collaborators Nov 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants