Skip to content

fix: keep parens around jsx that starts a member, call or new expression - #889

Merged
dsherret merged 2 commits into
mainfrom
fix-jsx-parens-before-member
Nov 4, 2026
Merged

dsherret merged 2 commits into
mainfrom
fix-jsx-parens-before-member

Conversation

@dsherret

@dsherret dsherret commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Single-line JSX lost the parens it needs when it starts a call, new, tagged template, non-null or instantiation expression, which produced code that doesn't parse. With the default jsx.multiLineParens: prefer:

// input
const a = new (<div />)();
const b = (<div />)();
const c = (<div />)!;

// output
const a = new <div />();
const b = <div />();
const c = <div />!;

With always, member access lost its parens as well ((<div />).props became <div />.props), and ((<div />))() was unstable with both. The paren expression is skipped in these positions, and the parens were only added back when the JSX was multi-line.

Single-line JSX now keeps its parens when it's the object of a member expression, the callee of a call, optional call or new, the tag of a tagged template, or the expression of a non-null or instantiation expression. Output only changes for this broken code. In the regression corpus I use, nothing changed.

never already kept these parens. Its check from #888 now uses the same helper, so the positions where parens are needed are listed in one place.

Tests

  • JsxElement_ParensNeeded_Prefer.txt, JsxElement_ParensNeeded_Always.txt and JsxElement_ParensNeeded_Never.txt cover JSX that's called, constructed, a tag, non-null, instantiated, the object of a member expression, multi-line JSX in those positions, and nested parens.

@dsherret
dsherret merged commit dd1a075 into main Nov 4, 2026
1 check passed
@dsherret
dsherret deleted the fix-jsx-parens-before-member branch November 4, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant