Skip to content

fix(codegen): don't inject parenthesis in optional chaining within new expressions#14170

Merged
graphite-app[bot] merged 1 commit intomainfrom
09-27-fix_codegen_don_t_inject_parenthesis_in_optional_chaining_within_new_expressions
Sep 27, 2025
Merged

fix(codegen): don't inject parenthesis in optional chaining within new expressions#14170
graphite-app[bot] merged 1 commit intomainfrom
09-27-fix_codegen_don_t_inject_parenthesis_in_optional_chaining_within_new_expressions

Conversation

@sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Sep 26, 2025

fixes #14127

@github-actions github-actions bot added A-codegen Area - Code Generation C-bug Category - Bug labels Sep 26, 2025
Copy link
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 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.

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 26, 2025

CodSpeed Instrumentation Performance Report

Merging #14170 will not alter performance

Comparing 09-27-fix_codegen_don_t_inject_parenthesis_in_optional_chaining_within_new_expressions (aa927ab) with main (402e6c7)1

Summary

✅ 37 untouched

Footnotes

  1. No successful run was found on main (06b16a9) during the generation of this report, so 402e6c7 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@sapphi-red sapphi-red changed the title fix(codegen): don't inject parenthesis in optional chaining within 'new' expressions fix(codegen): don't inject parenthesis in optional chaining within new expressions Sep 26, 2025
@sapphi-red sapphi-red marked this pull request as ready for review September 26, 2025 17:26
Copy link
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 codegen issue where parentheses were incorrectly being injected around optional chaining expressions within new expressions. The fix ensures that optional chaining operators (?.) are properly preserved without unwanted parentheses when used inside function or class constructors invoked with new.

  • Updates context handling for Function and Class expressions to disable call parentheses injection
  • Adds comprehensive test cases covering both function and class expressions with optional chaining

Reviewed Changes

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

File Description
crates/oxc_codegen/src/gen.rs Modified context handling for Function and Class expressions to prevent unwanted parentheses injection
crates/oxc_codegen/tests/integration/js.rs Added test cases verifying optional chaining works correctly within new expressions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Member

@Boshen Boshen left a comment

Choose a reason for hiding this comment

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

It seems like this is controlled by hasNonOptionalChainParent in esbuild. Our codegen should align with esbuild exactly.

@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Sep 27, 2025
Copy link
Member

Boshen commented Sep 27, 2025

Merge activity

@graphite-app graphite-app bot force-pushed the 09-27-fix_codegen_don_t_inject_parenthesis_in_optional_chaining_within_new_expressions branch from d113b09 to aa927ab Compare September 27, 2025 09:48
@graphite-app graphite-app bot merged commit aa927ab into main Sep 27, 2025
27 checks passed
@graphite-app graphite-app bot deleted the 09-27-fix_codegen_don_t_inject_parenthesis_in_optional_chaining_within_new_expressions branch September 27, 2025 09:54
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-codegen Area - Code Generation C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

codegen: parenthesis is injected in optional chaining mistakenly

3 participants