Enter a search term above to see results...
On This Page
TemplateCompiler
The TemplateCompiler
class is responsible for compiling template strings into an Abstract Syntax Tree (AST). This precompilation step enables efficient rendering and updates, especially useful for server-side rendering (SSR) and advanced use cases.
Constructor
Syntax
Parameters
Name | Type | Description |
---|---|---|
templateString | string | The template string to compile |
Usage
Methods
compile
Compiles the template string into an Abstract Syntax Tree (AST).
Syntax
Returns
Object
- The compiled [AST]](/api/templating/ast) representation of the template.
Usage
parseTemplateString
Parses a template string, typically used for partial templates or snippets.
Syntax
Parameters
Name | Type | Description |
---|---|---|
expression | string | The template string to parse |
Returns
Object
- An object containing parsed template information.
Usage
detectSyntax
Detects whether the template uses single {}
or double {{}}
bracket syntax.
Syntax
Parameters
Name | Type | Description |
---|---|---|
templateString | string | The template string to analyze |
Returns
string
- Either 'singleBracket'
or 'doubleBracket'
.
Usage
preprocessTemplate
Preprocesses the template string, handling special cases like self-closing web component tags.
Syntax
Parameters
Name | Type | Description |
---|---|---|
templateString | string | The template string to preprocess |
Returns
string
- The preprocessed template string.
Usage
optimizeAST
Optimizes the compiled AST by joining neighboring HTML nodes.
Syntax
Parameters
Name | Type | Description |
---|---|---|
ast | Object[] | The AST to optimize |
Returns
Object[]
- The optimized AST.
Usage
Server Side Compilations
You can precompile your templates on the serve then load them on the client using modern build tooling like esbuild or rollup and JSON imports.
Server
On the server we want to render our templates to an AST.
Client
Then on the client we can import that files directly as JSON
file directly and pass as the ast
parameter in defineComponent
.