Skip to content

feat(tsrx-prettier-plugin): Phase 1 formatting decisions, Prettier-style parse errors, and fixes (#503, #504, #505, #509) - #511

Merged
leonidaz merged 11 commits into
mainfrom
feat/tsrx-prettier-plugin-roadmap
Sep 25, 2026
Merged

leonidaz merged 11 commits into
mainfrom
feat/tsrx-prettier-plugin-roadmap

Conversation

@leonidaz

@leonidaz leonidaz commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

What this PR is

This is the working PR for the next phase of tsrx-prettier-plugin, the candidate successor to @tsrx/prettier-plugin. The first version landed in #409. This description holds the plan, the decisions made so far, and everything needed to pick the work up, including by another agent. Work lands here as commits, and this description is updated as items are done.

It lands Phase 1 of the plan, and the user decided it merges now, so the plan continues in a new PR when work on the plugin resumes. The changes, all in the private package:

Closes #503, closes #504, closes #505, closes #509.

Background

@tsrx/prettier-plugin prints every JavaScript and TypeScript node itself (over 13,000 lines), and it kept drifting from Prettier: dozens of open "Formatter … like Prettier" issues. tsrx-prettier-plugin (packages/tsrx-prettier-plugin, private, not published) instead reuses Prettier's own printer (prettier/plugins/estree) and prints only TSRX syntax itself. It is tested against Prettier's own format tests.

Current state (this branch: main at 4005d382 plus this PR's commits)

Prettier cases imported (JS, JSX, TS from Prettier 3.9.6 that apply to TSRX) 2040
Pass 2023: every imported case except the deliberate skips (2040 imported, from 5,114 Prettier cases in these areas; the rest are error, cursor, or range tests, or not TSX)
Known failures (tests/prettier-known-failures.json) 0
Skipped by override (tests/prettier-overrides.js) 17: 8 private-field destructuring (#424), 6 error-recovery-only inputs (#415), 2 CommonJS await(…), 1 line-starting < after a callee
Repository .tsrx files all 69 format without errors, and a second format changes nothing
prettier/standalone works with only this plugin (a test covers it)

Decisions so far

The user made these decisions during #409 and the parser PRs. Keep to them unless the user says otherwise.

  1. Prettier parity. Output is exactly what Prettier prints with its typescript parser for the same TSX. TSRX differs only where its syntax does. Differences from Prettier are bugs, even where @tsrx/prettier-plugin did something else on purpose.
  2. JSX layout follows Prettier: parentheses around multi-line JSX, and a forced break for an element with more than one attribute plus children. Templates format like the same JSX in a regular function.
  3. TSRX values lay out like JSX. A directive (@if/@for/@switch/@try), or a @{ … } block used as a value, is wrapped in ( … ) where it's assigned, returned, thrown, or an arrow body, with its comments inside the parentheses. A @{ … } function or arrow body stays on its line. This matches @tsrx/prettier-plugin on main. The one deliberate difference: a leading line comment before a directive in an assignment (const y = // c) prints the way Prettier prints a JSX element there.
  4. Comments between JSX children are comments (// and /* */). TSX reads them as text. They keep their line.
  5. A .tsrx file is a strict-mode ES module and TSX-like. A lone arrow type parameter is written <T,>. Namespaced tags aren't supported. Prettier cases that aren't valid TSX, or not valid in a strict module, are left out at import.
  6. JSX spread children ({...items}) parse, but are unsupported on every target. Core's analyzer reports tsrx-jsx-spread-child: fatal in a compile, collected in editor mode (fix(core): parse JSX spread children and report them as unsupported (#417) #495).
  7. An operator on the next line continues an element statement, as in TSX ([Bug]: tsrx-core: Parser ends an element statement before an operator on the next line, where TSX continues the expression #496). A < that starts a line is the next element (the TSRX rule), except where only type parameters can follow a name ([Bug]: tsrx-core: Parser rejects type parameters that start on the line after a declaration name #419).
  8. Proposal-only syntax isn't supported until it becomes JavaScript. Its Prettier cases are skipped with a reason, and the issue is closed as not planned ([Bug]: tsrx-core: Parser rejects destructuring of private fields (const { #x: x } = this) #424).
  9. @tsrx/prettier-plugin's tests aren't the expected output for this plugin. They are still being changed. Any comparison goes in its own place, and differences are review items (see work item 1).
  10. <script> bodies are formatted only when they hold JavaScript or TypeScript (no type, module, or a JS/TS type), with this plugin's own parser. Anything else is kept as written.
  11. Markup the parser had to recover (an unclosed or mismatched tag) is a formatting error, not guessed output.
  12. No switch until the user is absolutely sure. Whether this plugin replaces @tsrx/prettier-plugin, or ships separately as tsrx-prettier-plugin, is one of the last decisions. Until then, nothing else in the repository moves to it, and the old plugin stays the one that's used and published.
  13. Upstream parser bugs are worked around locally. When a parser bug's cause is in acorn or @sveltejs/acorn-typescript, override that one method in TSRXPlugin (packages/tsrx/src/plugin.js) and file the issue upstream. Mark the override with // UPSTREAM(<repo>#<issue>): remove once a release includes the fix, and list it in the "Upstream workarounds" table below, so it can be found and removed later.
  14. Type-check-level errors are collected in collect mode ([Bug]: tsrx-core: Parser throws on mistakes that TypeScript reports only as type-check diagnostics, even with collect: true #415). These are mistakes TypeScript only reports as diagnostics, such as a redeclared type, abstract outside an abstract class, an ambient initializer, or optional-chaining assignment. In collect and loose mode the parser records them and keeps parsing; a normal compile still throws. Inputs that only TypeScript's error recovery accepts (6 Prettier cases) are skipped with a reason, like proposal syntax.
  15. A missing } is reported as '}' expected, like TypeScript, not as acorn's generic Unexpected token. This applies to every block, template and JavaScript alike.
  16. A // comment between < and a tag name goes on its own indented line after <, as @tsrx/prettier-plugin prints it since fix(core): start an element at its <, and continue an element statement across a line break (#467, #496) #500. Prettier's own output (<// note with div on the next line) isn't valid TSX, and Prettier can't re-parse it. The exception is an element's direct child, which keeps <// note: there, a < followed by a line break is text (core's literal-< rule, so a < b works in text), and the layout would turn the element into text.
  17. A block comment on its own line between < and a tag name prints straight away in the form Prettier's second pass settles on, </* note */ div />. That's Prettier parity, and it's stable. The same goes for a closing tag (</ /* note */ div>), where Prettier's first format is unstable too.
  18. A < that starts a line is an element, even after a callee (foo followed by <string>(1) on the next line). This is what makes semicolon-less templates work (const label = "hi" followed by <string>{label}</string>). Prettier's typescript/call/callee-comments.ts is skipped as a TSRX difference.
  19. A comment before a directive or @{ … } value follows Prettier's JSX layout, which is already the case. const y = // lead then @if … keeps the comment after =. A comment on its own line after = goes inside the parentheses (const y = ( / // lead / @if …).

Remaining work

The order the user set: Phase 1 first, then the open parser issues (in progress as separate core PRs), then Phase 3. Phase 2 is on hold: the user doesn't want this plugin tested against @tsrx/prettier-plugin's tests for now. Phase 1 is complete: every item is merged or in this PR, and there are no known failures. This PR can merge once the user is happy with it (it only touches the private package, so it needs no changeset); Phase 2 then continues in a new working PR that carries this plan over.

Phase 1: parser fixes and formatting decisions

The parser fixes are separate PRs against @tsrx/core, each from its own worktree, and can run in parallel where they touch different code. The formatting decisions land in this PR. After each parser PR merges, merge main into this PR, re-import, and refresh the known failures (see the runbook).

# Work Where Status
1.1 #439 (static before a line break becomes a field name, a miscompile), #420 (generic call signature as an interface's first member), #421 (class global {}), #423 (import "x" then assert (…) on the next line). Each: override the acorn-typescript method (decision 13), file the upstream issue, and add tests. core PR merged (#551)
1.2 #422: import attributes in import types (import("./a.json", { with: … })). Override tsParseImportType to parse the options object into TSImportType.options, and file the upstream issue. @tsrx/prettier-plugin prints TSImportType itself, so it must learn to print options in the same PR, or it would drop them. This plugin's adapter already keeps options for Prettier's printer; confirm it prints them. core PR merged (#555)
1.3 #415: collect the type-check-level errors in collect mode (decision 14). Route acorn's and acorn-typescript's raise/raiseRecoverable through one allow-list of these messages. Handle the two unexpected() cases: pass checkPrivateFields: false when collecting, and accept a const without an initializer when collecting. A normal compile keeps throwing. core PR merged (#558)
1.4 '}' expected for a missing } (decision 15), for template and JavaScript blocks alike. It touches error reporting, like 1.3, so it goes after 1.3 or is coordinated with it. File the issue first. core PR merged (#590, issue #583)
1.5 Formatting decisions in this plugin: 16 (a // comment before a tag name gets its own line), 17 (a block comment on its own line prints as </* note */ div />), 18 (skip callee-comments.ts with its reason), and skip #415's 6 error-recovery inputs with their reason. Decision 19 needs no change: it already matches Prettier in both placements. this PR done (f5d17da)

Upstream workarounds (decision 13). Add a row when an override lands, and remove it when the upstream fix is released and the override is gone:

Override in plugin.js tsrx issue Upstream issue Removed when
tsParseModifier, tsParseModifiers (#551) #439 sveltejs/acorn-typescript#119 a release fixes #119
tsParseInterfaceBody (#551) #420 sveltejs/acorn-typescript#120 a release fixes #120
parseClassId (#551) #421 sveltejs/acorn-typescript#110 (open PR) a release includes #110
parseMaybeImportAttributes (#551) #423 sveltejs/acorn-typescript#121 a release fixes #121
tsParseImportType (#555) #422 sveltejs/acorn-typescript#110 (open PR) a release includes #110
esrap TSImportType options printed in tsx_with_ts_locations (#555) #422 sveltejs/esrap#231 an esrap release prints options
CHECKER_LEVEL_ERRORS allow-list through raise/raiseRecoverable, and canAwait in namespaces (#558) #415 sveltejs/acorn-typescript#89 upstream decides #89 and a release follows it
optional binding-pattern entry in the allow-list (#558) #415 sveltejs/acorn-typescript#110 (open PR) a release includes #110
modifier errors recorded at the modifier's offset (#558) #415 sveltejs/acorn-typescript#122 a release fixes #122

All rows are live: #551, #555 and #558 are merged.

Where an open upstream issue or PR already covers a cause, the override references it instead of a new issue:

The adapter in this plugin has one workaround of its own: it wraps export import in an ExportNamedDeclaration for sveltejs/acorn-typescript#114 (src/parse.js, TSImportEqualsDeclaration). The user's other open acorn-typescript items are #111 (tsrx #169), #112 with its fix #113 (tsrx #194; #421's override touches the same parseClassId, so coordinate), and #116 (tsrx #342).

Follow-up issues found during Phase 1

Filed, not part of Phase 1, and open unless noted:

Known failures today

None. #551, #555 and #558 fixed every parser cause, and this PR skips the 7 cases TSRX reads differently on purpose (decision 18 and #415's error-recovery inputs). From here on, a new known failure means a regression or a new Prettier release.

Phase 2: compare with @tsrx/prettier-plugin's tests (on hold)

On hold by the user's decision: don't test this plugin against the old plugin's tests for now. When it resumes: Run the old plugin's test suite (packages/prettier-plugin/src/index.test.js: 826 tests, input → format() → toBeWithNewline(expected)) against this plugin, and sort every difference into:

  • (a) TSRX behavior this plugin should have. The old test captures something TSRX-specific that is right, and this plugin gets it wrong. Fix it here, and add a test to tests/tsrx.test.js.
  • (b) The old plugin deviates from Prettier. Keep this plugin's output (decision 1), and note it in the report.
  • (c) Needs a decision. It's TSRX-specific and neither output is clearly right. For example, the old plugin hugs a @{ … } that is an element's only child (<div>@{ … }</div>). List these for the user.

How:

  • Run the file with its plugin import pointed at packages/tsrx-prettier-plugin/src/index.js, from a scratch copy or with a vitest alias. Don't change the old plugin or its tests.
  • Collect each failing test's input, old expected output, and new output.
  • Group the failures by cause, and post the classified report in this PR. For (c), ask the user.
  • The old tests are in flux, so rerun this before acting on it.

Phase 3: more TSRX tests

Write them from the language rules and Prettier's behavior, not from the old plugin's tests. Areas that aren't covered yet:

  • nested directives
  • @for heads that break, with destructuring, index and key
  • comments in directive heads and between @else branches
  • @{ … } inside JSX attributes and expression containers
  • <style apply> variants and assigned themes
  • dynamic tags with attributes and children
  • semi: false, singleQuote, bracketSameLine, singleAttributePerLine for TSRX syntax

Ongoing: keeping up with Prettier

  • On a Prettier upgrade, run pnpm --filter tsrx-prettier-plugin import-prettier-tests, then refresh the known failures.
  • Keep src/jsx.js (copied from Prettier's printJsxElementInternal and printJsxChildren) in step with Prettier.
  • Check the adapter against Prettier's src/language-js/parse/postprocess: node shapes the printer expects can change between releases.

Last: the release decision (the user decides)

Nothing moves to this plugin until the user is absolutely sure (decision 12). Phases 1–3 are what build that confidence. When the time comes, the user chooses between:

  • Replacing @tsrx/prettier-plugin: publish this plugin under that name.
  • Releasing it separately as tsrx-prettier-plugin, next to or instead of the old one.

Either way, these would need doing, so check each one with the user before touching it:

  • Settle the name, options, and version (a changeset, not major).
  • Move whichever consumers should use it:
    • the root package.json and .prettierrc
    • .changeset/config.json (the fixed group)
    • packages/language-server/src/server.js
    • packages/tsrx-mcp (src/format.js, src/server.js, src/inspect.js, tests)
    • website-tsrx (package.json, src/routes.ts, src/pages/getting-started.tsrx)
    • READMEs
  • Format the repository with it and review the diff.
  • Hook it into the playground (it already works in prettier/standalone).
  • If it replaces the old plugin, retire the old plugin's issue backlog: many "Formatter …" issues become moot.

Runbook

# Set up a worktree from main (never work on main directly)
git fetch origin && git worktree add -b <branch> ../<dir> origin/main
cd ../<dir> && pnpm install --frozen-lockfile --ignore-scripts

# Test (about 10 s), typecheck, format
pnpm vitest run --project tsrx-prettier-plugin
npx tsgo --noEmit -p packages/tsrx-prettier-plugin/tsconfig.typecheck.json
npx prettier --check packages/tsrx-prettier-plugin

# After a parser fix lands on main: merge main in (don't rebase a pushed branch),
# re-import (clones Prettier at the installed version, or pass --source), and
# refresh the known failures
git merge origin/main && pnpm install --frozen-lockfile --ignore-scripts
node packages/tsrx-prettier-plugin/scripts/import-prettier-tests.js [--source <prettier checkout>]
UPDATE_KNOWN_FAILURES=1 pnpm vitest run --project tsrx-prettier-plugin
pnpm vitest run --project tsrx-prettier-plugin

To check the repository's .tsrx files (no errors, and a second format changes nothing), run this from packages/tsrx-prettier-plugin:

node --input-type=module -e "
import * as prettier from 'prettier'; import plugin from './src/index.js'; import fs from 'node:fs'; import { execSync } from 'node:child_process';
const files = execSync('cd ../.. && git ls-files \"*.tsrx\"', { encoding: 'utf8' }).trim().split('\n');
const o = { parser: 'tsrx', plugins: [plugin], useTabs: true, singleQuote: true, printWidth: 100, bracketSameLine: false };
for (const f of files) { const src = fs.readFileSync('../../' + f, 'utf8'); try { const a = await prettier.format(src, o); if ((await prettier.format(a, o)) !== a) console.log('unstable', f); } catch (e) { console.log('error', f, e.message.split('\n')[0]); } }"

Conventions

  • Findings: file an issue for every finding with a distinct root cause, using the bug template's sections (Issue Category, Bug Description, Reproduction Steps with real output, Cause with permalinks, Fix Direction, Environment, Additional Context). Verify on current main and check for duplicates first. A finding with the same root cause as the current PR goes in its description instead.
  • Parser fixes are separate PRs, one per root cause or small group, from their own worktree. They're complete when opened (not drafts), with a patch changeset for @tsrx/core, and verified by comparing ASTs before and after over the repository's .tsrx files, the test-file sources, and the Prettier snapshot inputs.
  • No git stash: refs/stash is shared by every worktree and other sessions run in parallel. Use patch files or WIP commits.
  • Anything that can hang (parser loops) runs under a hard kill: spawnSync(…, { timeout, killSignal: 'SIGKILL' }) or a Worker with terminate(), since timeout isn't installed. Use at most 4 workers, and isolate tests in a Worker or child process, because a vitest timeout can't stop a synchronous loop. Check ps afterwards.
  • Cursor Bugbot findings: reproduce them and push your own fix. Ignore Bugbot's autofix.
  • Merging: the user merges; main needs a review, and agents can't merge.
  • Clean-up: after a merge, remove that PR's worktree once git status is clean and the local branch head matches the PR's last commit.
  • Changesets: changes limited to this private package need no changeset. Core or @tsrx/prettier-plugin changes need a patch changeset (major is rejected).

Open questions for the user

None right now. The order of work is Phase 1, then Phases 2 and 3, and the release decision comes last. Upstream issues for the Phase 1 overrides are filed from the user's GitHub account, as part of each fix.

🤖 Generated with Claude Code


Note

Low Risk
Changes are limited to the private formatter package, are covered by Prettier import tests and new TSRX tests, and affect output formatting rather than runtime or security behavior.

Overview
Completes Phase 1 of the experimental tsrx-prettier-plugin: README documents current parser/printer behavior and the test layout; Prettier parity for several edge cases; known Prettier import failures drop to zero (remaining mismatches are explicit skips).

Parser (parse.js) normalizes failures through createParseError (1-based loc.start, message shape like Prettier’s parsers). textWithoutComments is shared so @case { and export import token positions ignore braces/import inside comments (#509). <style> / <script> bodies get tsrxRawText when embedded formatting is off (#503).

Printer (printer.js) adds comment placement aligned with if/try/else: @if/@try hook estree handleComments; printBeforeBranch / @for @empty handling (#505); @catch comments before @; printTagNameComments so // before a tag name is valid TSX (#504-style nested @{ … } treated as a statement, not a parenthesized value). embeddedLanguageFormatting: "off" prints style/script via printRawTextAsWritten.

Tests: expanded tsrx.test.js; prettier-known-failures.json cleared; prettier-overrides.js skips TypeScript-only error-recovery cases, line-start < after a callee, and related cases.

Reviewed by Cursor Bugbot for commit e847ab3. Bugbot is set up for automated code reviews on this repo. Configure here.

leonidaz and others added 3 commits September 25, 2026 11:01
Cover what was added after the first version: recovered markup is an error,
comments between JSX children and `src/jsx.js`, JSX-style parentheses for
`@{ … }` values and directives, `<script>` body types, standalone use, and
the kinds of overrides.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ADME

Whether this plugin replaces `@tsrx/prettier-plugin` or is released on its
own is one of the last decisions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…kip cases TSRX reads differently

- A line comment between `<` and a tag name goes on its own indented line,
  with the name and attributes below it, as Prettier lays out a closing tag
  (Prettier's `<// note` isn't TSX). An element's direct child keeps Prettier's
  layout, since a `<` followed by a line break there is text.
- A block comment before a tag name prints straight after `<` or `</`, in the
  form Prettier's second format settles on.
- Skip Prettier's `callee-comments.ts` (a line-starting `<` is an element in
  TSRX) and the 6 inputs only TypeScript's error recovery parses (#415).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

leonidaz added a commit that referenced this pull request Sep 25, 2026
Regenerated prettier-known-failures.json: the 7 cases #511 skips remain.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

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 using default effort and found 2 potential issues.

Autofix Details

Bugbot Autofix prepared a fix for 1 of the 2 issues found in the latest run.

  • ✅ Fixed: Dynamic tag comments are dropped
    • Commented tag names are now printed for every name node, including a dynamic JSXExpressionContainer, so a comment between < and {Tag} is kept.

Create PR

Or push these changes by commenting:

@cursor push 06e93e38a8
Preview (06e93e38a8)
diff --git a/packages/tsrx-prettier-plugin/src/printer.js b/packages/tsrx-prettier-plugin/src/printer.js
--- a/packages/tsrx-prettier-plugin/src/printer.js
+++ b/packages/tsrx-prettier-plugin/src/printer.js
@@ -423,6 +423,11 @@
 function printTsrx(path, options, print) {
 	const { node, parent } = path;
 
+	// `willPrintOwnComments` claims every commented tag name, including a
+	// dynamic `<{Tag}>` whose name is a `JSXExpressionContainer`. Print it
+	// here; otherwise Prettier skips the comment.
+	if (isCommentedTagName(path)) return printTagNameComments(path, options, print);
+
 	switch (node.tsrxType ?? node.type) {
 		case 'BlockStatement':
 			return node.tsrxCodeBlock
@@ -452,11 +457,6 @@
 			return node.commentType === 'Line' ? [printed, breakParent] : printed;
 		}
 
-		case 'JSXIdentifier':
-		case 'JSXMemberExpression':
-		case 'JSXNamespacedName':
-			return isCommentedTagName(path) ? printTagNameComments(path, options, print) : null;
-
 		case 'JSXAttribute':
 			return node.shorthand ? ['{', print(['value', 'expression']), '}'] : null;
 

diff --git a/packages/tsrx-prettier-plugin/tests/tsrx.test.js b/packages/tsrx-prettier-plugin/tests/tsrx.test.js
--- a/packages/tsrx-prettier-plugin/tests/tsrx.test.js
+++ b/packages/tsrx-prettier-plugin/tests/tsrx.test.js
@@ -521,6 +521,48 @@
 		);
 	});
 
+	// A dynamic name is a `JSXExpressionContainer`. Its leading comment is still
+	// a tag-name comment, so it keeps the same layout as a static name.
+	test('a comment before a dynamic tag name is kept', async () => {
+		await expectFormat(
+			`const d = <
+  // note
+  {Tag} a="1">x</{Tag}>;
+const e = <div>
+  <// note
+    {Foo.Bar} />
+</div>;
+const f = <{Tag}>x</
+  // note
+  {Tag}>;
+const g = <
+  /* note */
+  {Tag} />;`,
+			`const d = (
+  <
+    // note
+    {Tag}
+    a="1"
+  >
+    x
+  </{Tag}>
+);
+const e = (
+  <div>
+    <// note
+    {Foo.Bar}
+    />
+  </div>
+);
+const f = <{Tag}>x</
+    // note
+    {Tag}
+  >;
+const g = </* note */ {Tag} />;
+`,
+		);
+	});
+
 	// Prettier prints this on its second format; its first keeps the line breaks.
 	test('a block comment on its own line prints straight after `<` or `</`', async () => {
 		await expectFormat(

You can send follow-ups to the cloud agent here.

…ugin-roadmap

# Conflicts:
#	packages/tsrx-prettier-plugin/tests/prettier-known-failures.json
leonidaz and others added 3 commits September 25, 2026 14:17
…rsers

Every parse error, not only broken markup, now carries Prettier's `loc.start`
with a 1-based column and ends its message with that position, so Prettier's
code frame marks where it is (`'}' expected. (4:1)`).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nch comments (#503, #504, #505, #509)

- With `embeddedLanguageFormatting: "off"`, `<style>` and `<script>` bodies are
  printed as written instead of being emptied or re-spaced (#503).
- A nested `@{ … }` in a template is a statement, not a value, so it isn't
  wrapped in parentheses, which made it unused output (#504).
- `@if` and `@try` present themselves as `if` and `try` to Prettier's comment
  handling, so comments before `@else` and `@catch` land where Prettier puts
  them before `else` and `catch`; `@catch`'s own comments print before its
  `@`, which a comment used to split (#505). A comment before `@empty` stays
  before it, like one before `else`.
- The `{` of an `@case` body, and the `import` of an `export import`, are found
  outside comments (#509).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@leonidaz leonidaz changed the title tsrx-prettier-plugin: plan and next steps toward replacing @tsrx/prettier-plugin feat(tsrx-prettier-plugin): Phase 1 formatting decisions, Prettier-style parse errors, and fixes (#503, #504, #505, #509) Sep 25, 2026
@leonidaz
leonidaz marked this pull request as ready for review September 25, 2026 18:44
leonidaz and others added 2 commits September 25, 2026 14:45
A comment between `<` and a dynamic tag's `{Tag}` was claimed by the tag-name
comment printing but never printed, which failed the format. A dynamic tag's
name now lays out its comments like any tag name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

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 using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue. You can view the agent here.

Reviewed by Cursor Bugbot for commit e847ab3. Configure here.

leonidaz added a commit that referenced this pull request Sep 27, 2026
…rs, and what an element renders around comments between its children (#630, #639) (#596)

* chore(tsrx-prettier-plugin): open the working PR for the plan after #511

The plan, decisions, and state carried over from #511 are in the PR
description. Work on the plugin lands here as commits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(tsrx-prettier-plugin): keep a comment in a class method's type parameters (#630)

The adapter moves a class method's type parameters onto its function, as
typescript-estree has them, and now also starts the function at them, so a
comment inside them belongs to the function instead of the method's name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(tsrx-prettier-plugin): keep what an element renders when a comment is between its children (#639)

A comment adds nothing to the text around it: the whitespace on its two sides
is one run (#615), which renders a space without a line break, and nothing
with one beside an element or the start or end of the children. The adapter
now describes each comment group's run (`describeCommentRuns`), including a
`{" "}` beside it, and `printCommentChild` prints a run that renders the same:
- a significant space is JSX whitespace, which prints `{" "}` where a line
  breaks, at the start or end of the children when the element breaks, and
  written out before a line comment, which ends its line;
- a line break at the start or end of the children breaks the element when a
  space in the run would otherwise render;
- whitespace and `{" "}`s in the run are printed by the comments;
- a line comment after another comment starts its own line, since the parser
  reads `/* c */ // c` as text.

Also fixes `isEmptyDoc`, which judged any doc starting with an empty string
empty, and lays out children with such a comment with `fill`, like text.

Checked on every sequence of up to three of text, an element, an expression,
`{" "}`, a block comment, and a line comment, with no separator, a space, or a
line break between them (12,546 cases): each renders the same after
formatting, and a second format changes nothing. Before, 137 of the 558
two-part cases didn't.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(tsrx-prettier-plugin): keep the space a {" "} beside a comment renders, and a {" "} with its own comment (#639)

- A `{" "}` in a comment's run counts as a space on its side of the comments,
  so it prints as the run's space instead of being dropped.
- Where the comments keep a line break inside the run, the run's space is
  written out as `{" "}`, since a plain space next to the line break is trimmed.
- A line comment after text starts its own line (on the text's line it is
  text) and always ends its line.
- The space around a group of comments goes on one side, chosen once, so a
  narrow line breaks in one place and the next format is stable.
- A `{" "}` with a comment inside is an ordinary child that prints its comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment