fix(es/base): Wrap new opt chain#11618
Conversation
🦋 Changeset detectedLatest 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 |
There was a problem hiding this comment.
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 invisit_mut_new_exprin 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.
Binary Sizes
Commit: 13ab020 |
There was a problem hiding this comment.
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.
Description:
BREAKING CHANGE:
Related issue (if exists):
Closes #11612