Use similar_functions tool to find all functions that handle template expression parsing.
I'll use the similar_functions tool to find functions that handle template expression parsing in the Svelte codebase.
Tool Call: Run MCP tool similar_functions
Status: Completed
Found 10 similar functions:
- TaggedTemplateExpression
- Path: /packages/svelte/src/compiler/phases/2-analyze/visitors/TaggedTemplateExpression.js:9-16
- Summary: Here's a summary for the
TaggedTemplateExpressionfunction:
This function handles tagged template expressions in JavaScript, taking a node and context as parameters. It checks if there's an active expression and if the template tag is not pure. If both conditions are met, it marks the expression as having a call and state. Finally, it advances to the next context state.
The function appears to be part of a code analysis or transformation system, specifically dealing with template literal expressions that have tags (e.g., tag`template`).
- transform_template
- Path: /packages/svelte/src/compiler/phases/3-transform/client/transform-template/index.js:38-68
- Summary: Here's a summary for the
transform_templatefunction:
This function transforms a component's template state into a function call expression. It handles both tree and HTML representations of templates, supports different namespaces (HTML, SVG, MathML), and includes special handling for script tags. In development mode, it adds source location information to the template. The function takes a component state object, namespace string, and optional flags as parameters, and returns a function call expression.
The function appears to be part of a template compilation system, likely for a UI framework or component library.
- element
- Path: /packages/svelte/src/compiler/phases/1-parse/state/element.js:52-417
- Summary: Here's a summary of the
elementfunction:
This function parses HTML/SVelte elements in a template, handling various element types and their attributes. It:
- Processes HTML comments
- Handles both opening and closing tags
- Validates element names and special Svelte tags
- Manages element attributes and directives
- Handles special cases for
<script>,<style>, and<textarea>elements - Supports self-closing tags and void elements
- Maintains a stack of nested elements
- Provides error handling for invalid syntax
- Supports loose parsing mode for incomplete/malformed markup
The function is a core part of Svelte's template parser, responsible for converting HTML-like syntax into an Abstract Syntax Tree (AST).
Parameters:
parser: A Parser instance that maintains the parsing state and provides utility methods
The function doesn't return a value but modifies the parser's state and AST structure.
- text
- Path: /packages/svelte/src/compiler/phases/1-parse/state/text.js:6-23
- Summary: Here's a summary of the
textfunction:
This function parses plain text content in a template until it encounters either a < or { character. It takes a Parser object as input, tracks the starting position, accumulates characters into a data string, and creates a Text node in the AST (Abstract Syntax Tree) with both raw text and decoded character references.
The function is primarily used for template parsing and handles the text content between HTML tags or template expressions.
- tag
- Path: /packages/svelte/src/compiler/phases/1-parse/state/tag.js:18-48
- Summary: Here's a summary for the
tagfunction:
This function parses different types of tags in a template/markup language. It handles:
- Opening tags (starting with #)
- Next tags (starting with :)
- Special tags (starting with @)
- Closing tags (starting with /)
- Expression tags (containing JavaScript expressions)
The function takes a Parser object as input, processes the tag based on its prefix, and appends the parsed result to the parser's output. For expression tags, it includes metadata about the expression.
- build_template_chunk
- Path: /packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/utils.js:39-125
- Summary: Here's a summary of the
build_template_chunkfunction:
This function processes an array of text nodes and expression tags to build a template literal or string literal expression. It:
- Takes an array of AST nodes (either Text or ExpressionTag), a component context, state, and a memoization function
- Combines text nodes and simple literal expressions directly into template strings
- Handles more complex expressions by:
- Evaluating them when possible
- Adding null coalescing operators where needed
- Memoizing expressions as configured
- Returns an object containing:
- A final expression (either a template literal or string literal)
- A boolean indicating if the template contains stateful expressions
The function is particularly useful for optimizing template rendering by consolidating multiple nodes into a single expression where possible.
- read_sequence
- Path: /packages/svelte/src/compiler/phases/1-parse/state/element.js:777-855
- Summary: Here's a summary of the
read_sequencefunction:
This function parses a template string to extract text and expression tags. It takes a Parser object, a completion check callback, and a location string as parameters. The function reads through the template character by character, identifying plain text and expressions wrapped in curly braces ({}). It handles special cases for block (#) and element (@) tags, validates their placement, and processes character references in text chunks. The function returns an array of Text and ExpressionTag nodes that represent the parsed template sequence.
Key features:
- Processes both plain text and expression tags
- Handles character reference decoding
- Validates block and element tag placement
- Supports loose parsing mode
- Returns an AST (Abstract Syntax Tree) fragment
- ExpressionTag
- Path: /packages/svelte/src/compiler/phases/2-analyze/visitors/ExpressionTag.js:11-26
- Summary: Here's a summary for the
ExpressionTagfunction:
/**
* Processes an expression tag within an AST, validating its placement within a template
* and marking the subtree as dynamic. Handles template context and expression metadata.
*
* @param {AST.ExpressionTag} node - The expression tag node to process
* @param {Context} context - The current compilation context
*/
This summary captures the main purposes of the function:
-
Processing expression tags
-
Validating tag placement in templates
-
Marking subtrees as dynamic
-
Managing context and expression metadata
-
template_effect
- Path: /packages/svelte/src/internal/client/reactivity/effects.js:335-353
- Summary: Here's a summary for the
template_effectfunction:
This function creates an effect for handling template expressions. It takes three parameters:
fn: A function that either accepts expressions or returns a void functionthunks: An array of thunk functions (optional)d: A function that creates derived values (optional)
In development mode, it wraps the effect with additional stack trace information. In all cases, it creates derived values from the thunks and executes the function with the resolved derived values as arguments. Returns an Effect object.
The function is primarily used for template handling in a reactive context, managing derived values and their effects.
- next
- Path: /packages/svelte/src/compiler/phases/1-parse/state/tag.js:437-548
- Summary: Here's a summary of the
nextfunction:
This function handles the parsing of continuation blocks in a template language, specifically processing:
elseandelse ifclauses forIfBlockselseclauses forEachBlocksthenandcatchclauses forAwaitBlocks
The function takes a parser object as input and updates the parser's state by:
- Validating correct syntax and token placement
- Creating appropriate fragments and block structures
- Managing the parser's stack and fragments
- Throwing errors for invalid or duplicate clauses
It's primarily used for parsing control flow structures in what appears to be a template or markup language parser.Total tokens used while classifying functions: 4561
Based on the search results, I found several functions that handle template expression parsing in the Svelte codebase. Here are the key functions:
-
read_sequence-/packages/svelte/src/compiler/phases/1-parse/state/element.js:777-855- This is a key function that parses template strings to extract text and expression tags
- Reads through templates character by character, identifying expressions wrapped in curly braces
{} - Returns an array of Text and ExpressionTag nodes
-
ExpressionTag-/packages/svelte/src/compiler/phases/2-analyze/visitors/ExpressionTag.js:11-26- Processes expression tag nodes within the AST
- Validates tag placement within templates
- Marks subtrees as dynamic and manages expression metadata
-
tag-/packages/svelte/src/compiler/phases/1-parse/state/tag.js:18-48- Parses different types of tags including expression tags containing JavaScript expressions
- Handles opening tags (#), next tags (:), special tags (@), and closing tags (/)
-
TaggedTemplateExpression-/packages/svelte/src/compiler/phases/2-analyze/visitors/TaggedTemplateExpression.js:9-16- Handles tagged template expressions in JavaScript (e.g.,
tag`template`) - Part of the analysis phase for template literal expressions
- Handles tagged template expressions in JavaScript (e.g.,
-
build_template_chunk-/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/utils.js:39-125- Processes arrays of text nodes and expression tags to build template literals
- Combines text nodes and expressions into optimized template strings
- Handles memoization and null coalescing for complex expressions
-
transform_template-/packages/svelte/src/compiler/phases/3-transform/client/transform-template/index.js:38-68- Transforms component template state into function call expressions
- Handles both tree and HTML representations of templates
-
template_effect-/packages/svelte/src/internal/client/reactivity/effects.js:335-353- Creates effects for handling template expressions in a reactive context
- Manages derived values and their effects
These functions work together to parse, analyze, and transform template expressions throughout the Svelte compilation pipeline, from initial parsing through final code generation.