#1528·ripple

[Bug]: Read an @case arm's body from the BlockStatement the next @tsrx/core gives

Author: leonidazCreated Sep 27, 2026Updated Sep 27, 2026

[!WARNING] Don't start until the @tsrx/core release that includes tsrx-org/tsrx#879 is published (0.5.0). Upgrade for it together with #1525, #1526 and #1527.

Issue Category

Other (preparing for the next @tsrx/core)

Bug Description

The next @tsrx/core gives an @case or @default arm its { … } body as a node (tsrx-org/tsrx#879, tsrx-org/tsrx#842):

tsrx
@switch (x) {
  @case 1: {
    const y = 1;
    <b>{y}</b>
  }
  @default: {
    // only a comment
  }
}
@case 1's consequent @default's consequent
@tsrx/core 0.3 / 0.4 [VariableDeclaration, JSXElement] []
@tsrx/core 0.5.0 [BlockStatement], whose body is [VariableDeclaration, JSXElement] [BlockStatement] with an empty body, the comment its inner comment

It is the shape every parser gives a JavaScript case 1: { … }, and the shape of the @if, @for and @try bodies. The block spans the arm's { to }, gets its own scope, and carries the same metadata as an @if body (native_tsrx_template_block: true, templateMode: 'script'). Plain JavaScript switch statements are unchanged.

What Ripple needs to do

Read at 97d090b9. About 6–8 places, 20–40 lines.

  1. is_template_child_position breaks. A node in an arm now has the parents BlockStatement → SwitchCase → JSXSwitchExpression, so the grandparent check fails, and a @{ … } in an @case is no longer analyzed as template output (caller: the analyzer's JSXCodeBlock visitor, analyze/index.js:2413). Accept a grandparent SwitchCase whose parent is a directive, as it does for CatchClause.
  2. An arm's scope: scopes.get(switch_case) || context.state.scope at client index.js:1884, 6129, 6745, and server index.js:1346, and 6433 through branch_returning_body. The arm's bindings are now in the block's scope, which flatten_switch_consequent skips. Prefer scopes.get(switch_case.consequent[0]).
  3. Empty arms: analyze/index.js:873, client 1882 and server 1344 test consequent.length === 0, which an empty @case x: {} no longer passes: it would get an empty branch instead of return; (a snapshot change, not a behavior change). Test the block's body.length.
  4. Optional: client 6754's consequent[0].type === 'BlockStatement' is now always true for @switch (it still works), and the comment at 6433–6435 ("an arm has no block node") is stale.

Already fine: flatten_switch_consequent (utils.js:2683), is_directive_render_position (utils.js:228), the SwitchStatement walks in utils.js and the client and server transforms (they recurse into BlockStatement), hoist.js (compiled output), and style-scopes.js.

Reproduction Steps

After upgrading, an @case body with a @{ … } or setup bindings, and an empty @case.

Environment

  • Ripple main at 97d090b9, @tsrx/core 0.3.x

Additional Context

  • tsrx-org/tsrx#879: the change. tsrx-org/tsrx#842: the issue.
  • Octane: octanejs/octane#1355. @tsrx/oxc: tsrx-org/oxc#128.

Checklist

  • I've searched for existing issues