Repository navigation
feat(core): give an @case or @default arm its { … } body as a BlockStatement - #879
Merged
Merged
Conversation
…Statement
An `@case`/`@default` arm always has a `{ … }` body, but core kept only
its statements, so the braces weren't a node (#842). Its `consequent` is
now one BlockStatement from the `{` to the `}`, as a JavaScript
`case 1: { … }` has in every parser and as the `@if`, `@for` and `@try`
bodies are, with the same template-block metadata. A comment in an empty
arm is the block's inner comment.
- tsrx-prettier-plugin: the adapter no longer rebuilds the block by
searching the source for the `{`.
- @tsrx/prettier-plugin: prints the arm's block like an `@if` body, and
keeps the comments of an empty `@switch` inside it (core's attachment
now treats an empty `@switch` like an empty `switch`), which fixes
#774.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 27, 2026
Closed
thejackshelton
added a commit
to tsrx-org/yuku
that referenced
this pull request
Sep 27, 2026
…n @tsrx/core 0.5.0
Each arm's consequent is now the one BlockStatement from its '{' to its '}',
the shape of a JavaScript 'case 1: { ... }' and of the @if, @for and @Try
bodies (tsrx-org/tsrx#879). The block is in the tree, so the scope analysis
no longer builds one per case after parsing; that code goes, and with it
the extra nodes that broke the attached-comment table (yuku#12).
Type parameter names are already Identifiers and enum members already sit
in a TSEnumBody; tests pin both.
1 task done
This was referenced Nov 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR changes
An
@caseor@defaultarm's{ … }body is now a node, as in every parser's tree for a JavaScriptcase 1: { … }:@case 1'sconsequent@default'sconsequent[VariableDeclaration, JSXElement][](the comment has no node to be in)[BlockStatement { … }]from the{to the}, holding both[BlockStatement { }], the comment its inner commentBabel, typescript-estree, oxc, SWC and acorn all give
case 1: { … }aconsequentof oneBlockStatement, and TypeScript oneBlock; only acasewithout braces has a flat list. An@casealways has braces. The@if,@forand@trybodies were already blocks, so@case/@defaultwas the only directive body that wasn't a node. The block carries the same template-block metadata as an@ifbody (native_tsrx_template_block,templateMode: 'script');returnstays invalid in an arm.What compiles and renders is unchanged: core's transform already handles a block in a case, and all five compilers and runtimes pass without a change.
Changes
@tsrx/core(minor, a breaking change to the tree; ships in 0.5.0): the parser wraps an arm's body in the block. The comment attachment keeps the comments of an empty@switchinside it, as it does for an emptyswitch(it checkednode.type, which isJSXSwitchExpression).tsrx-prettier-plugin(private): the adapter no longer rebuilds the block by searching the source for the{(−19 lines; a brace in a comment once crashed that search, [Bug]: tsrx-prettier-plugin crashes on a brace in a comment before an @switch arm #509).@tsrx/prettier-plugin(patch): prints an arm's block as it prints an@ifbody, and an empty@switchbody's comments inside it. This fixes [Bug]: tsrx-core: The comments in an empty template @switch, @case, or @default body move out of it, and one before its { moves before the ) or : #774 (every row of its table), matching Prettier 3.9.9'sswitch. One row moved in Prettier itself since the issue: 3.9.9 movesswitch (a) /* e */ {toswitch (a /* e */) {, so the formatter does too (on [PLAN]: tsrx-prettier-plugin: plan, decisions, and the Phase 1 queue #852's list of Prettier bugs).Verification
pnpm format:checkandpnpm changeset:check.@tsrx/prettier-plugin, stable on a second format.tsrx-prettier-plugin's directive test (fix(tsrx-prettier-plugin): keep a comment in an empty @switch body #878) passes unchanged without the rebuild.Downstream
Surveyed at Ripple
97d090b9and Octaneb7bade7c:@{ … }in an arm, the arm's scope lookup, and the empty-arm checks.@switchlowering (universal, client and SSR), each needing the block'sbody.@tsrx/oxc(Give an @case or @default arm its { … } body as a BlockStatement, as the next @tsrx/core does oxc#128): has to give the same tree.Closes #842.
Closes #774.
🤖 Generated with Claude Code