fix(parser): fix conditional expressions with arrow-function alternates in TS#20356
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via 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. |
There was a problem hiding this comment.
Pull request overview
Fixes a TypeScript parsing edge case where conditional expressions involving arrow functions (notably with TS return type annotations) could be parsed incorrectly, and adds a misc coverage case to exercise the scenario.
Changes:
- Adjusted arrow-function parsing to respect
allow_return_type_in_arrow_functionwhen the arrow head is unambiguous. - Added a new misc/pass TypeScript coverage case for a conditional expression whose alternate is an arrow function with an explicit return type.
- Updated coverage snapshots to reflect the additional misc case (and its current semantic-transform-check outcome).
Reviewed changes
Copilot reviewed 1 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
crates/oxc_parser/src/js/arrow.rs |
Fixes conditional/arrow parsing behavior by honoring the return-type allowance flag for parenthesized arrows. |
tasks/coverage/misc/pass/conditional-arrow-alternate-return-type.ts |
Adds a repro-style misc pass case covering a conditional with an arrow-function alternate using a TS return type. |
tasks/coverage/snapshots/parser_misc.snap |
Snapshot updated for the new misc case count. |
tasks/coverage/snapshots/transformer_misc.snap |
Snapshot updated for the new misc case count. |
tasks/coverage/snapshots/codegen_misc.snap |
Snapshot updated for the new misc case count. |
tasks/coverage/snapshots/formatter_misc.snap |
Snapshot updated for the new misc case count. |
tasks/coverage/snapshots/semantic_misc.snap |
Snapshot updated; now records an additional semantic transform-check mismatch triggered by the new misc case. |
You can also share your feedback on Copilot code review. Take the survey.
Merging this PR will not alter performance
Comparing Footnotes
|
Merge activity
|
c0452b9 to
78c264a
Compare
### 🚀 Features - e7163b6 ecmascript: Add known-globals to side-effect-free property reads (#20212) (Dunqing) - 139ab68 ecmascript: Add `property_write_side_effects` to `MayHaveSideEffectsContext` (#20217) (Dunqing) ### 🐛 Bug Fixes - 78c264a parser: Fix conditional expressions with arrow-function alternates in TS (#20356) (camc314) - 5c97b14 minifier: Recognize object spread of object literals as side-effect-free (#20299) (Boshen) - 1ff5c1d transformer/typescript: Rewrite extensions in dynamic `import()` expressions (#20121) (Sverre Johansen) - 1c07b3b diagnostics: Handle `WouldBlock` in stdout writes to prevent panic (#20295) (Boshen) - ade14d4 ecmascript: Enhance side-effect detection for classes, TypedArrays, computed members, and spread (#20213) (Dunqing) ### ⚡ Performance - 5474d0a semantic: V8-style walk-up reference resolution (#20292) (Boshen) ### 📚 Documentation - e4aa5b5 parser/napi, linter/plugins: Add JSDoc comments to raw transfer constants (#20286) (overlookmotel) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>

fixes rolldown/rolldown#8676