PRISM compile pass

When a source file's JSX runtime is @bext-stack/framework, bext-turbopack runs prism_compile::optimize on the source BEFORE tsc-rs sees it. Static-foldable subtrees collapse to JS string literals; dynamic JSX (function children, runtime ternaries with non-string branches, component invocations whose body isn't statically foldable) falls through to the runtime h() helper.

Tip
Toggle the pass off with BEXT_PRISM_COMPILE=0 in /etc/default/nginx to compare the raw tsc-rs output against the folded output — useful for debugging why a subtree isn't being folded. The pass is idempotent: applying it twice produces the same result.

Selected before / after pairs

PatternSource (TSX)After compile pass
static element with text<h1>Hello</h1>"<h1>Hello</h1>"
interpolated text<h1>Hello, {name}!</h1>"<h1>Hello, " + (name) + "!</h1>"
attribute<a href={url}>{text}</a>'<a href="' + __bextEsc(url) + '">' + (text) + "</a>"
ternary class (folded with __bextEsc)<div className={cond ? "a" : "b"}>{kid}</div>'<div class="' + __bextEsc(cond ? "a" : "b") + '">' + (kid) + "</div>"
list .map (folded inline)<ul>{items.map(i => <li>{i}</li>)}</ul>"<ul>" + (items).map((i) => "<li>" + (i) + "</li>").join("") + "</ul>"
fully static subtree<div><h1>Hi</h1><p>fixed text</p></div>"<div><h1>Hi</h1><p>fixed text</p></div>"
dynamic root component (bails)<Header title="x"><Page /></Header>(falls through to runtime jsx() — components are only inlined when their body is a static-foldable JSX expression)

Why it matters

  • Static text and elements skip the runtime tag-formatting cost entirely — they're string literals at the bundle level.
  • Attribute interpolation goes through __bextEsc at compile time, so XSS protection is wired in even when the runtime h() helper isn't called.
  • Dynamic shapes can be folded if every leaf is a string literal or the shape pattern is recognized. The fall-through to h() is correct, just slower per-element.

Toggle off with BEXT_PRISM_COMPILE=0 at compile time to see the un-folded shape (useful for diffing build output).