Skip to content

fix(generator): improve new callee parens check#18046

Merged
JLHwung merged 1 commit into
babel:mainfrom
JLHwung:fix-18045
Jun 4, 2026
Merged

fix(generator): improve new callee parens check#18046
JLHwung merged 1 commit into
babel:mainfrom
JLHwung:fix-18045

Conversation

@JLHwung

@JLHwung JLHwung commented Jun 4, 2026

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? Fixes #18045
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

In this PR we improve the new callee needsParens logic: It now covers the tagged template and the TS non-null expressions as well. The recursive call has been replaced by plain loop as well.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: generator labels Jun 4, 2026
@babel-bot

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/61717

@pkg-pr-new

pkg-pr-new Bot commented Jun 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: bb98cf0


// The following outer parentheses can be removed
new f![g()]();
new (f?.g!.h)();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This change reveals another generator bug:

(f?.g!).h should not be printed as f?.g!.h because the optional chain coverage will be changed. I will fix this in a new PR.

@JLHwung JLHwung merged commit c43ea9b into babel:main Jun 4, 2026
57 checks passed
@JLHwung JLHwung deleted the fix-18045 branch June 4, 2026 17:03
JLHwung added a commit to JLHwung/babel that referenced this pull request Jun 4, 2026
JLHwung added a commit to JLHwung/babel that referenced this pull request Jun 5, 2026
JLHwung added a commit to JLHwung/babel that referenced this pull request Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: generator PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@babel/generator missing parentheses in some edge case of NewExpression

4 participants