Skip to content

feat(minifier): merge assign expression against member expression in conditional expression#24706

Merged
graphite-app[bot] merged 1 commit into
mainfrom
07-20-feat_minifier_merge_assign_expression_against_member_expression_in_conditional_expression
Jul 21, 2026
Merged

feat(minifier): merge assign expression against member expression in conditional expression#24706
graphite-app[bot] merged 1 commit into
mainfrom
07-20-feat_minifier_merge_assign_expression_against_member_expression_in_conditional_expression

Conversation

@sapphi-red

@sapphi-red sapphi-red commented Jul 20, 2026

Copy link
Copy Markdown
Member

Compress x ? a.b = 0 : a.b = 1 to a.b = x ? 0 : 1.

refs #8345

@github-actions github-actions Bot added the A-minifier Area - Minifier label Jul 20, 2026

sapphi-red commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

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 changes, fast-track this PR to the front of 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.

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

@sapphi-red
sapphi-red force-pushed the 07-20-feat_minifier_merge_assign_expression_against_member_expression_in_conditional_expression branch from 99bfafb to 53ee4a5 Compare July 20, 2026 08:29
@codspeed-hq

codspeed-hq Bot commented Jul 20, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 57 untouched benchmarks
⏩ 19 skipped benchmarks1


Comparing 07-20-feat_minifier_merge_assign_expression_against_member_expression_in_conditional_expression (3d43bc1) with main (0e9b460)

Open in CodSpeed

Footnotes

  1. 19 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.

@sapphi-red
sapphi-red marked this pull request as ready for review July 20, 2026 08:50
@Dunqing

Dunqing commented Jul 20, 2026

Copy link
Copy Markdown
Member

I noticed that #24699 is merging and will conflict with this PR. I will help resolve it after the merge.

@Dunqing
Dunqing force-pushed the 07-20-feat_minifier_merge_assign_expression_against_member_expression_in_conditional_expression branch from 53ee4a5 to 1a13333 Compare July 20, 2026 09:35
@sapphi-red
sapphi-red force-pushed the 07-20-feat_minifier_merge_assign_expression_against_member_expression_in_conditional_expression branch from 1a13333 to 3d43bc1 Compare July 20, 2026 10:32
@Dunqing

Dunqing commented Jul 20, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d43bc1d4f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/oxc_minifier/src/peephole/mod.rs
Comment thread crates/oxc_minifier/src/peephole/mod.rs
@graphite-app graphite-app Bot added the 0-merge Merge with Graphite Merge Queue label Jul 21, 2026
@graphite-app

graphite-app Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Merge activity

…conditional expression (#24706)

Compress `x ? a.b = 0 : a.b = 1` to `a.b = x ? 0 : 1`.

refs #8345
@graphite-app
graphite-app Bot force-pushed the 07-20-feat_minifier_merge_assign_expression_against_member_expression_in_conditional_expression branch from 3d43bc1 to 03a54c9 Compare July 21, 2026 03:31
@graphite-app
graphite-app Bot merged commit 03a54c9 into main Jul 21, 2026
29 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Jul 21, 2026
@graphite-app
graphite-app Bot deleted the 07-20-feat_minifier_merge_assign_expression_against_member_expression_in_conditional_expression branch July 21, 2026 03:35
graphite-app Bot pushed a commit that referenced this pull request Jul 21, 2026
Conditional assignment merging can move a `this` member target ahead of a `super()` condition. In a derived constructor, that rewrites valid source into an access of uninitialized `this`, causing a `ReferenceError`.

Keep reorder-sensitive `this` targets guarded until the first unconditional top-level `super()` call in a derived constructor. This preserves the optimization after `super()` has initialized `this`, including the real-world Terser fixture that caused the earlier size increase.

## Example

Input:

```js
class B extends A {
  constructor() {
    super() ? (this.b = 0) : (this.b = 1);
  }
}
```

Before:

```js
class B extends A{constructor(){this.b=+!super()}}
```

After:

```js
class B extends A{constructor(){super()?this.b=0:this.b=1}}
```

Verified with the full `oxc_minifier` suite (625 passed, 42 ignored), Clippy with warnings denied, formatting, `just minsize`, allocation regeneration, and byte-for-byte comparison of all 12 minsize outputs against `main`. Minsize and allocation snapshots are unchanged.

Addresses the wrong-code issue raised in #24706 (comment).

Implemented with AI assistance (OpenAI Codex). The contributor remains responsible for reviewing, understanding, and submitting the changes under the repository AI usage policy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants