} values
* @param {(node: SvelteNode, state: any) => any} visit
* @param {ComponentClientTransformState} state
- * @returns {{ value: Expression, has_state: boolean, has_call: boolean, can_inline: boolean }}
+ * @returns {{ value: Expression, has_state: boolean, has_call: boolean }}
*/
export function build_template_chunk(values, visit, state) {
/** @type {Expression[]} */
@@ -25,23 +25,15 @@ export function build_template_chunk(values, visit, state) {
let has_call = false;
let has_state = false;
- let can_inline = true;
let contains_multiple_call_expression = false;
for (const node of values) {
if (node.type === 'ExpressionTag') {
- if (node.metadata.expression.has_call) {
- if (has_call) contains_multiple_call_expression = true;
- has_call = true;
- }
-
- if (node.metadata.expression.has_state) {
- has_state = true;
- }
+ const metadata = node.metadata.expression;
- if (!node.metadata.expression.can_inline) {
- can_inline = false;
- }
+ contains_multiple_call_expression ||= has_call && metadata.has_call;
+ has_call ||= metadata.has_call;
+ has_state ||= metadata.has_state;
}
}
@@ -50,49 +42,39 @@ export function build_template_chunk(values, visit, state) {
if (node.type === 'Text') {
quasi.value.cooked += node.data;
+ } else if (node.type === 'ExpressionTag' && node.expression.type === 'Literal') {
+ if (node.expression.value != null) {
+ quasi.value.cooked += node.expression.value + '';
+ }
} else {
- const expression = /** @type {Expression} */ (visit(node.expression, state));
-
- if (expression.type === 'Literal') {
- if (expression.value != null) {
- quasi.value.cooked += expression.value + '';
- }
+ if (contains_multiple_call_expression) {
+ const id = b.id(state.scope.generate('stringified_text'));
+ state.init.push(
+ b.const(
+ id,
+ create_derived(
+ state,
+ b.thunk(
+ b.logical(
+ '??',
+ /** @type {Expression} */ (visit(node.expression, state)),
+ b.literal('')
+ )
+ )
+ )
+ )
+ );
+ expressions.push(b.call('$.get', id));
+ } else if (values.length === 1) {
+ // If we have a single expression, then pass that in directly to possibly avoid doing
+ // extra work in the template_effect (instead we do the work in set_text).
+ return { value: visit(node.expression, state), has_state, has_call };
} else {
- let value = expression;
-
- // if we don't know the value, we need to add `?? ''` to replace
- // `null` and `undefined` with the empty string
- let needs_fallback = true;
-
- if (value.type === 'Identifier') {
- const binding = state.scope.get(value.name);
-
- if (binding && binding.initial?.type === 'Literal' && !binding.reassigned) {
- needs_fallback = binding.initial.value === null;
- }
- }
-
- if (needs_fallback) {
- value = b.logical('??', expression, b.literal(''));
- }
-
- if (contains_multiple_call_expression) {
- const id = b.id(state.scope.generate('stringified_text'));
-
- state.init.push(b.const(id, create_derived(state, b.thunk(value))));
-
- expressions.push(b.call('$.get', id));
- } else if (values.length === 1) {
- // If we have a single expression, then pass that in directly to possibly avoid doing
- // extra work in the template_effect (instead we do the work in set_text).
- return { value: visit(node.expression, state), has_state, has_call, can_inline };
- } else {
- expressions.push(value);
- }
-
- quasi = b.quasi('', i + 1 === values.length);
- quasis.push(quasi);
+ expressions.push(b.logical('??', visit(node.expression, state), b.literal('')));
}
+
+ quasi = b.quasi('', i + 1 === values.length);
+ quasis.push(quasi);
}
}
@@ -102,7 +84,7 @@ export function build_template_chunk(values, visit, state) {
const value = b.template(quasis, expressions);
- return { value, has_state, has_call, can_inline };
+ return { value, has_state, has_call };
}
/**
diff --git a/packages/svelte/src/compiler/phases/nodes.js b/packages/svelte/src/compiler/phases/nodes.js
index 13a54730eb..ead525aaa1 100644
--- a/packages/svelte/src/compiler/phases/nodes.js
+++ b/packages/svelte/src/compiler/phases/nodes.js
@@ -58,7 +58,6 @@ export function create_expression_metadata() {
return {
dependencies: new Set(),
has_state: false,
- has_call: false,
- can_inline: true
+ has_call: false
};
}
diff --git a/packages/svelte/src/compiler/types/index.d.ts b/packages/svelte/src/compiler/types/index.d.ts
index bd4749db00..8a45f2d4fd 100644
--- a/packages/svelte/src/compiler/types/index.d.ts
+++ b/packages/svelte/src/compiler/types/index.d.ts
@@ -317,8 +317,6 @@ export interface ExpressionMetadata {
has_state: boolean;
/** True if the expression involves a call expression (often, it will need to be wrapped in a derived) */
has_call: boolean;
- /** True if the expression can be inlined into a template */
- can_inline: boolean;
}
export * from './template.js';
diff --git a/packages/svelte/src/internal/client/index.js b/packages/svelte/src/internal/client/index.js
index bfc0a6aac9..6fd749b42c 100644
--- a/packages/svelte/src/internal/client/index.js
+++ b/packages/svelte/src/internal/client/index.js
@@ -1,5 +1,4 @@
export { FILENAME, HMR, NAMESPACE_SVG } from '../../constants.js';
-export { escape_html as escape } from '../../escaping.js';
export { cleanup_styles } from './dev/css.js';
export { add_locations } from './dev/elements.js';
export { hmr } from './dev/hmr.js';
diff --git a/packages/svelte/tests/migrate/samples/slot-non-identifier/output.svelte b/packages/svelte/tests/migrate/samples/slot-non-identifier/output.svelte
index fb262e8c25..b9a3248012 100644
--- a/packages/svelte/tests/migrate/samples/slot-non-identifier/output.svelte
+++ b/packages/svelte/tests/migrate/samples/slot-non-identifier/output.svelte
@@ -82,4 +82,4 @@
cool
-
+
\ No newline at end of file
diff --git a/packages/svelte/tests/snapshot/samples/inline-module-vars/_expected/client/index.svelte.js b/packages/svelte/tests/snapshot/samples/inline-module-vars/_expected/client/index.svelte.js
deleted file mode 100644
index 4622624424..0000000000
--- a/packages/svelte/tests/snapshot/samples/inline-module-vars/_expected/client/index.svelte.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import "svelte/internal/disclose-version";
-import * as $ from "svelte/internal/client";
-
-const __DECLARED_ASSET_0__ = "__VITE_ASSET__2AM7_y_a__ 1440w, __VITE_ASSET__2AM7_y_b__ 960w";
-const __DECLARED_ASSET_1__ = "__VITE_ASSET__2AM7_y_c__ 1440w, __VITE_ASSET__2AM7_y_d__ 960w";
-const __DECLARED_ASSET_2__ = "__VITE_ASSET__2AM7_y_e__ 1440w, __VITE_ASSET__2AM7_y_f__ 960w";
-const __DECLARED_ASSET_3__ = "__VITE_ASSET__2AM7_y_g__";
-const a = 1;
-const b = 2;
-var root = $.template(` ${a} + ${b} = ${$.escape(a + b ?? "")}
`, 1);
-
-export default function Inline_module_vars($$anchor) {
- var fragment = root();
-
- $.next(2);
- $.append($$anchor, fragment);
-}
\ No newline at end of file
diff --git a/packages/svelte/tests/snapshot/samples/inline-module-vars/_expected/server/index.svelte.js b/packages/svelte/tests/snapshot/samples/inline-module-vars/_expected/server/index.svelte.js
deleted file mode 100644
index ca98cd952b..0000000000
--- a/packages/svelte/tests/snapshot/samples/inline-module-vars/_expected/server/index.svelte.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import * as $ from "svelte/internal/server";
-
-const __DECLARED_ASSET_0__ = "__VITE_ASSET__2AM7_y_a__ 1440w, __VITE_ASSET__2AM7_y_b__ 960w";
-const __DECLARED_ASSET_1__ = "__VITE_ASSET__2AM7_y_c__ 1440w, __VITE_ASSET__2AM7_y_d__ 960w";
-const __DECLARED_ASSET_2__ = "__VITE_ASSET__2AM7_y_e__ 1440w, __VITE_ASSET__2AM7_y_f__ 960w";
-const __DECLARED_ASSET_3__ = "__VITE_ASSET__2AM7_y_g__";
-const a = 1;
-const b = 2;
-
-export default function Inline_module_vars($$payload) {
- $$payload.out += ` ${$.escape(a)} + ${$.escape(b)} = ${$.escape(a + b)}
`;
-}
\ No newline at end of file
diff --git a/packages/svelte/tests/snapshot/samples/inline-module-vars/index.svelte b/packages/svelte/tests/snapshot/samples/inline-module-vars/index.svelte
deleted file mode 100644
index a7b737e596..0000000000
--- a/packages/svelte/tests/snapshot/samples/inline-module-vars/index.svelte
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-{a} + {b} = {a + b}