function / @typed/template

templateToHtmlChunks

Converts a parsed Template into a sequence of HtmlChunks. This optimization pre-calculates the static HTML strings to minimize work at render time.

Package version
1.0.0-beta.7
Category
HTML compilation
Since
1.0.0

Import

import { templateToHtmlChunks } from "@typed/template";

Signatures

export declare function templateToHtmlChunks({ nodes }: Template.Template): readonly HtmlChunk[];

Why

Compiling the parsed AST once exposes static output immediately and assigns a context-specific serializer to each dynamic part.

Ownership and lifetime

The returned chunks retain the parsed nodes but own no reactive input. A RenderTemplate layer may cache them by template-literal identity.

Trust boundary

Dynamic serializers escape data for node, attribute, comment, and text-only contexts; renderer-owned HTML transport remains a separate brand.

Examples

import { templateToHtmlChunks } from "@typed/template/HtmlChunk"
import { parse } from "@typed/template/Parser"

const template = parse(["<div class=\"container\">Hello ", "</div>"])
const chunks = templateToHtmlChunks(template)

// chunks is an array of HtmlChunk objects
// Static parts are pre-rendered as text chunks
// Dynamic parts are represented as part chunks

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source