Repository navigation
Description
Warning
Don't start until the @tsrx/core release that includes tsrx-org/tsrx#879 is published (0.5.0), and the @tsrx/oxc release that follows it. Upgrade both together, with #1338, #1353 and #1354.
Summary
The next @tsrx/core gives an @case or @default arm its { … } body as a node (tsrx-org/tsrx#879, tsrx-org/tsrx#842):
@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 Octane needs to do
Read at b7bade7c. @switch lowers through b.switch(n.discriminant, n.cases) (compile.js:21206, 23783), so every SwitchStatement reader below sees the new arms. About 5 places, 10–20 lines plus a helper (e.g. armStatements(c) returning c.consequent[0].body, or statementsOf(c.consequent[0])):
compile-universal.js:3577breaks:compileBlockValueAst([Block])reads the block as setup, so the arm renders nothing.makeSwitchCallbreaks: it passes[Block]tounionEnvandhoistBodyHelper.makeIfCall(30719) already unwraps.body.ssrEmitSwitchbreaks: it passes[Block]tossrCompileSub, andcanBorrowSsrHostBranchRangenow always returns false.ssrEmitIf(14509) already unwraps.collectSingleRootIfDeps(compile.js:7747) andanchorlessRootShape(7813) silently lose their optimization (they find no output nodes). Passclause.consequent[0]instead of the array.
Already fine: renderer-boundaries.js:458, hydrate-boundaries.js:1019, style-scopes.js, slot-hooks.js, inline-hook-memo.js, hook-deps.js, strong-mode.js (they recurse into BlockStatement), and volar.js:759 (reads only keyword).
References
- feat(core): give an @case or @default arm its { … } body as a BlockStatement tsrx-org/tsrx#879: the change. [Bug]: tsrx-core, tsrx-prettier-plugin: An
@caseor@defaultbody's{ … }isn't a node, so the formatter rebuilds it by searching the source for the brace tsrx-org/tsrx#842: the issue. - [Bug]: Read an @case arm's body from the BlockStatement the next @tsrx/core gives Ripple-TS/ripple#1528: Ripple's side. Give an @case or @default arm its { … } body as a BlockStatement, as the next @tsrx/core does tsrx-org/oxc#128:
@tsrx/oxc's side.
Activity
fix: address the TSRX 0.5 upgrade issues
fix: update the TSRX toolchain to @tsrx/core 0.5 and the new formatter (