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(minifier): compress a == null && b to a ?? b when return value is ignored #8749

Conversation

sapphi-red
Copy link
Contributor

@sapphi-red sapphi-red commented Jan 27, 2025

Compress a == null && b to a ?? b when return value is ignored

When a is null or undefined, a == null && b returns b.
When a is not null or undefined, a == null && b returns false.

When a is null or undefined, a ?? b returns b.
When a is not null or undefined, a ?? b returns a.

References

Copy link
Contributor Author

sapphi-red commented Jan 27, 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.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added A-minifier Area - Minifier C-enhancement Category - New feature or request labels Jan 27, 2025
@sapphi-red sapphi-red marked this pull request as ready for review January 27, 2025 10:36
Copy link

codspeed-hq bot commented Jan 27, 2025

CodSpeed Performance Report

Merging #8749 will not alter performance

Comparing 01-27-feat_minifier_compress_a_null_b_to_a_b_when_return_value_is_ignored (f7f2d2f) with main (a3b078a)

Summary

✅ 33 untouched benchmarks

Copy link

graphite-app bot commented Jan 27, 2025

Merge activity

…ue is ignored (#8749)

Compress `a == null && b` to `a ?? b` when return value is ignored

When `a` is `null` or `undefined`, `a == null && b` returns `b`.
When `a` is not `null` or `undefined`, `a == null && b` returns `false`.

When `a` is `null` or `undefined`, `a ?? b` returns `b`.
When `a` is not `null` or `undefined`, `a ?? b` returns `a`.

**References**
- [Spec of `??`](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-binary-logical-operators-runtime-semantics-evaluation)
@Boshen Boshen force-pushed the 01-27-feat_minifier_support_a_0_and_this.a_in_has_no_side_effect_for_evaluation_same_target_ branch from 8a64c58 to 3c1c92c Compare January 27, 2025 14:31
@Boshen Boshen force-pushed the 01-27-feat_minifier_compress_a_null_b_to_a_b_when_return_value_is_ignored branch from 2ff3de0 to f7f2d2f Compare January 27, 2025 14:31
Base automatically changed from 01-27-feat_minifier_support_a_0_and_this.a_in_has_no_side_effect_for_evaluation_same_target_ to main January 27, 2025 14:38
@graphite-app graphite-app bot merged commit f7f2d2f into main Jan 27, 2025
27 checks passed
@graphite-app graphite-app bot deleted the 01-27-feat_minifier_compress_a_null_b_to_a_b_when_return_value_is_ignored branch January 27, 2025 14:42
@oxc-bot oxc-bot mentioned this pull request Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0-merge Merge with Graphite Merge Queue A-minifier Area - Minifier C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant