TSRX Enables JSX with Native JS Control Flow
Better Stackgo watch the original →
the gist
TSRX compiles linear components using 'component' keyword, if/for-of/try-catch statements, and no return to React/Solid/Vue/Ripple.
The Breakthrough
TSRX compiles UI components written with normal JavaScript control flow—including if statements, for-of loops, switch statements, and try-catch blocks—directly into JSX for React, Solid, Vue, Preact, and Ripple, without requiring a return statement.
What Actually Worked
- Components declare
componentinstead offunction; JSX statements render linearly wherever placed, with barereturnonly for early exits. - Conditional rendering uses standard
if/else if/elseorswitchwith JSX in blocks; compiler handles framework equivalents. - Lists render via extended
for-ofloop that exposesindexandkey, supportscontinueto skip items; other loops unsupported. - Error boundaries use
try/catch; async addspendingblock, compiled tolazyin React/Preact/Solid or Ripple equivalent. - Hooks place after conditions/loops/returns; compiler hoists them to top for stable order.
- Lexical scoping per element/if/for/switch/try prevents variable conflicts.
- Scoped styles via
<style>block attach unique hash to classes;stylekeyword passes hash to child components. - Text requires double quotes or template literals;
textkeyword escapes HTML strings safely,htmlkeyword renders them (Ripple fully, Vue subset). - Lazy destructuring uses
&propsfor per-access reactivity in Solid/Vue/Ripple. - Prop shorthand omits value for same-name props, like
{onchange}.
Context
JSX forces expression-based control flow, leading to nested ternaries for conditions, map for lists, strict hook ordering, and function wrappers for switches. TSRX extracts Ripple's syntax into a compiler (Vite plugin) for multiple frameworks, prioritizing linear readability and colocation of logic/UI/styles. It adds compiler magic like hook hoisting and scoping, which aids ergonomics but may complicate debugging.
The author demos features via code blocks, notes personal preference for React/JSX/Tailwind despite Claude generating TSRX code, and sees appeal for Ripple/Svelte users.
Notable Quotes
- "TSRX uses statementbased JSX so you don't need to return a component tree you just write your markup wherever you want it to render."
- "The compiler just quietly hoists every hook to the top of the generated function so React still sees them in a stable order but you get to write them where they actually belong."
- "Every nested element is creating its own scope so we're able to declare a const label in three different div blocks here and they don't collide."