diff --git a/.changeset/eighty-dragons-search.md b/.changeset/eighty-dragons-search.md
new file mode 100644
index 0000000000..83a72c88e8
--- /dev/null
+++ b/.changeset/eighty-dragons-search.md
@@ -0,0 +1,5 @@
+---
+'svelte': patch
+---
+
+perf: inline module variables into template
diff --git a/packages/svelte/src/compiler/phases/3-transform/client/types.d.ts b/packages/svelte/src/compiler/phases/3-transform/client/types.d.ts
index e44cc0239c..cf41afc0d5 100644
--- a/packages/svelte/src/compiler/phases/3-transform/client/types.d.ts
+++ b/packages/svelte/src/compiler/phases/3-transform/client/types.d.ts
@@ -54,7 +54,10 @@ export interface ComponentClientTransformState extends ClientTransformState {
/** Stuff that happens after the render effect (control blocks, dynamic elements, bindings, actions, etc) */
readonly after_update: Statement[];
/** The HTML template string */
- readonly template: string[];
+ readonly template: {
+ push_quasi: (q: string) => void;
+ push_expression: (e: Expression) => void;
+ };
readonly locations: SourceLocation[];
readonly metadata: {
namespace: Namespace;
diff --git a/packages/svelte/src/compiler/phases/3-transform/client/utils.js b/packages/svelte/src/compiler/phases/3-transform/client/utils.js
index d1a825d231..9463d909bc 100644
--- a/packages/svelte/src/compiler/phases/3-transform/client/utils.js
+++ b/packages/svelte/src/compiler/phases/3-transform/client/utils.js
@@ -311,3 +311,18 @@ export function create_derived_block_argument(node, context) {
export function create_derived(state, arg) {
return b.call(state.analysis.runes ? '$.derived' : '$.derived_safe_equal', arg);
}
+
+/**
+ * Whether a variable can be referenced directly from template string.
+ * @param {import('#compiler').Binding | undefined} binding
+ * @returns {boolean}
+ */
+export function can_inline_variable(binding) {
+ return (
+ !!binding &&
+ // in a `
+
+