Skip to content

fix(es/base): Wrap new opt chain#11618

Merged
kdy1 merged 2 commits intoswc-project:mainfrom
Austaras:main
Mar 7, 2026
Merged

fix(es/base): Wrap new opt chain#11618
kdy1 merged 2 commits intoswc-project:mainfrom
Austaras:main

Conversation

@Austaras
Copy link
Copy Markdown
Member

@Austaras Austaras commented Mar 4, 2026

Description:

BREAKING CHANGE:

Related issue (if exists):
Closes #11612

@Austaras Austaras requested a review from a team as a code owner March 4, 2026 09:18
Copilot AI review requested due to automatic review settings March 4, 2026 09:18
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 4, 2026

🦋 Changeset detected

Latest commit: dcf413b

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug (#11612) where the SWC minifier emitted syntactically invalid JavaScript when inlining an optional chain expression as the callee of a new expression (e.g., producing new XE?.default({...e}) which is a SyntaxError). The fix adds Expr::OptChain(..) to the match arm in the fixer's visit_mut_new_expr so that optional chain expressions used directly as new callees are automatically wrapped in parentheses (producing the valid new (XE?.default)({...e})).

Changes:

  • Added Expr::OptChain(..) to the callee-wrapping match in visit_mut_new_expr in the fixer pass.
  • Added a fixture test case (issues-11xxx/11612) with input, .swcrc, and expected output to verify the fix.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
crates/swc_ecma_transforms_base/src/fixer.rs Core fix: wraps optional chain callee in new expressions with parentheses
crates/swc/tests/fixture/issues-11xxx/11612/input/index.js Test input reproducing the reported bug
crates/swc/tests/fixture/issues-11xxx/11612/input/.swcrc Config enabling compression (which triggers collapse_vars/reduce_vars)
crates/swc/tests/fixture/issues-11xxx/11612/output/index.js Expected correct output with new (XE?.default)({...e})

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 4, 2026

Binary Sizes

File Size
swc.linux-x64-gnu.node 28M (28744264 bytes)

Commit: 13ab020

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 4, 2026

Merging this PR will not alter performance

✅ 192 untouched benchmarks


Comparing Austaras:main (dcf413b) with main (1c51891)

Open in CodSpeed

Comment thread crates/swc/tests/fixture/issues-11xxx/11612/output/index.js
Copilot AI review requested due to automatic review settings March 7, 2026 00:27
@kdy1 kdy1 requested a review from a team as a code owner March 7, 2026 00:27
Copy link
Copy Markdown
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.

Thanks!

@kdy1 kdy1 merged commit fdcd184 into swc-project:main Mar 7, 2026
40 checks passed
@github-actions github-actions Bot added this to the Planned milestone Mar 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@github-actions github-actions Bot modified the milestones: Planned, 1.15.21 Mar 22, 2026
@swc-project swc-project locked as resolved and limited conversation to collaborators Apr 22, 2026
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.

minifier causes invalid optional chain from new expression

4 participants