Skip to content

fix: preserve parentheses around IIFE callee in prettier plugin#784

Merged
leonidaz merged 2 commits intomainfrom
fix/iife-parentheses-formatting
Mar 5, 2026
Merged

fix: preserve parentheses around IIFE callee in prettier plugin#784
leonidaz merged 2 commits intomainfrom
fix/iife-parentheses-formatting

Conversation

@anubra266
Copy link
Copy Markdown
Collaborator

@anubra266 anubra266 commented Mar 5, 2026

Summary

Fixes #783.

The prettier plugin was stripping the wrapping parentheses from IIFE callees, turning valid syntax like:

const s = (() => {
  return true;
})();

into invalid syntax:

const s = () => {
  return true;
}();

The parser already marks parenthesized expressions with metadata.parenthesized = true, but the CallExpression printer never checked this flag on the callee node. The fix wraps the printed callee in () when node.callee.metadata?.parenthesized is 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 CallExpression printing to preserve required parentheses when the callee was originally parenthesized and is an ArrowFunctionExpression/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.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
new-website Ready Ready Preview, Comment Mar 5, 2026 3:28pm
ripple Ready Ready Preview, Comment Mar 5, 2026 3:28pm

Request Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 5, 2026

@ripple-ts/adapter

pnpm add https://pkg.pr.new/@ripple-ts/adapter@784

@ripple-ts/adapter-bun

pnpm add https://pkg.pr.new/@ripple-ts/adapter-bun@784

@ripple-ts/adapter-node

pnpm add https://pkg.pr.new/@ripple-ts/adapter-node@784

@ripple-ts/cli

pnpm add https://pkg.pr.new/@ripple-ts/cli@784

create-ripple

pnpm add https://pkg.pr.new/create-ripple@784

@ripple-ts/eslint-parser

pnpm add https://pkg.pr.new/@ripple-ts/eslint-parser@784

@ripple-ts/eslint-plugin

pnpm add https://pkg.pr.new/@ripple-ts/eslint-plugin@784

@ripple-ts/prettier-plugin

pnpm add https://pkg.pr.new/@ripple-ts/prettier-plugin@784

ripple

pnpm add https://pkg.pr.new/ripple@784

@ripple-ts/rollup-plugin

pnpm add https://pkg.pr.new/@ripple-ts/rollup-plugin@784

@ripple-ts/typescript-plugin

pnpm add https://pkg.pr.new/@ripple-ts/typescript-plugin@784

@ripple-ts/vite-plugin

pnpm add https://pkg.pr.new/@ripple-ts/vite-plugin@784

commit: 2367750

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

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, ')'];
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is good feedback actually, we should fix it

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@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

Copy link
Copy Markdown

@cursor cursor bot Mar 5, 2026

Choose a reason for hiding this comment

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

All good — thanks for confirming.
No further changes needed on this branch for that review thread.

Open in Web Open in Cursor 

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

oops my bad, this was already fixed. didn't see it on my phone.

@leonidaz leonidaz force-pushed the fix/iife-parentheses-formatting branch from 76bb448 to f0d78e0 Compare March 5, 2026 15:27
@leonidaz leonidaz merged commit d38c8f2 into main Mar 5, 2026
10 checks passed
@leonidaz leonidaz deleted the fix/iife-parentheses-formatting branch March 5, 2026 15:29
@github-actions github-actions bot mentioned this pull request Mar 5, 2026
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.

[Bug]: Ripple formating removes the wrapping brackets of IIFEs

3 participants