fix: preserve parentheses around IIFE callee in prettier plugin#784
fix: preserve parentheses around IIFE callee in prettier plugin#784
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@ripple-ts/adapter
@ripple-ts/adapter-bun
@ripple-ts/adapter-node
@ripple-ts/cli
create-ripple
@ripple-ts/eslint-parser
@ripple-ts/eslint-plugin
@ripple-ts/prettier-plugin
ripple
@ripple-ts/rollup-plugin
@ripple-ts/typescript-plugin
@ripple-ts/vite-plugin
commit: |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| // Preserve parentheses around the callee (e.g. IIFEs like `(() => {})()`) | ||
| if (node.callee.metadata?.parenthesized) { | ||
| calleePart = ['(', calleePart, ')']; | ||
| } |
There was a problem hiding this comment.
Double parentheses for parenthesized identifier callees
Medium Severity
When the callee is a parenthesized Identifier (e.g., (foo)()), the Identifier printer already adds parentheses because CallExpression is not in its parentHandlesParens check. The new CallExpression code then wraps the already-parenthesized output again, producing ((foo))(). The parentHandlesParens guard in the Identifier case needs to also exclude CallExpression, or the CallExpression check needs to be limited to callee types like ArrowFunctionExpression and FunctionExpression that don't self-parenthesize.
Additional Locations (1)
There was a problem hiding this comment.
This is good feedback actually, we should fix it
There was a problem hiding this comment.
@cursor add a fix to this branch and do this logic: the CallExpression check needs to be limited to callee types like ArrowFunctionExpression and FunctionExpression that don't self-parenthesize.
Add more tests as necessary
There was a problem hiding this comment.
oops my bad, this was already fixed. didn't see it on my phone.
76bb448 to
f0d78e0
Compare




Summary
Fixes #783.
The prettier plugin was stripping the wrapping parentheses from IIFE callees, turning valid syntax like:
into invalid syntax:
The parser already marks parenthesized expressions with
metadata.parenthesized = true, but theCallExpressionprinter never checked this flag on the callee node. The fix wraps the printed callee in()whennode.callee.metadata?.parenthesizedis true, consistent with how other node types handle this flag throughout the printer.Note
Medium Risk
Small but correctness-sensitive change in the core call-expression printer that can affect formatted output across many files; risk is mitigated by targeted regression tests for the previously broken IIFE cases.
Overview
Fixes the prettier plugin’s
CallExpressionprinting to preserve required parentheses when the callee was originally parenthesized and is anArrowFunctionExpression/FunctionExpression, preventing IIFE output from being reformatted into invalid syntax.Adds regression tests covering IIFE arrow/function callees and ensuring already-parenthesized identifier callees aren’t double-wrapped, and includes a patch changeset for
@ripple-ts/prettier-plugin.Written by Cursor Bugbot for commit 76bb448. This will update automatically on new commits. Configure here.