diff --git a/packages/svelte/src/internal/server/index.js b/packages/svelte/src/internal/server/index.js index 3fcee27a99..edda74c566 100644 --- a/packages/svelte/src/internal/server/index.js +++ b/packages/svelte/src/internal/server/index.js @@ -1,3 +1,5 @@ +/** @import { Component, Payload, RenderOutput } from '#server' */ +/** @import { Store } from '#shared' */ import { is_promise, noop } from '../shared/utils.js'; import { subscribe_to_store } from '../../store/utils.js'; import { @@ -37,36 +39,33 @@ export const VoidElements = new Set([ 'wbr' ]); -/** @returns {import('#server').Payload} */ -function create_payload() { - return { out: '', head: { title: '', out: '', anchor: 0 }, anchor: 0 }; -} - /** - * @param {import('#server').Payload} to_copy - * @returns {import('#server').Payload} + * @param {Payload} to_copy + * @returns {Payload} */ -export function copy_payload(to_copy) { +export function copy_payload({ out, head }) { return { - ...to_copy, - head: { ...to_copy.head } + out, + head: { + title: head.title, + out: head.out + } }; } /** * Assigns second payload to first - * @param {import('#server').Payload} p1 - * @param {import('#server').Payload} p2 + * @param {Payload} p1 + * @param {Payload} p2 * @returns {void} */ export function assign_payload(p1, p2) { p1.out = p2.out; p1.head = p2.head; - p1.anchor = p2.anchor; } /** - * @param {import('#server').Payload} payload + * @param {Payload} payload * @param {string} tag * @param {() => void} attributes_fn * @param {() => void} children_fn @@ -104,10 +103,11 @@ export let on_destroy = []; * @template {Record} Props * @param {import('svelte').Component | import('svelte').ComponentType>} component * @param {{ props?: Omit; context?: Map }} [options] - * @returns {import('#server').RenderOutput} + * @returns {RenderOutput} */ export function render(component, options = {}) { - const payload = create_payload(); + /** @type {Payload} */ + const payload = { out: '', head: { title: '', out: '' } }; const prev_on_destroy = on_destroy; on_destroy = []; @@ -115,7 +115,7 @@ export function render(component, options = {}) { if (options.context) { push(); - /** @type {import('#server').Component} */ (current_component).c = options.context; + /** @type {Component} */ (current_component).c = options.context; } // @ts-expect-error @@ -137,8 +137,8 @@ export function render(component, options = {}) { } /** - * @param {import('#server').Payload} payload - * @param {(head_payload: import('#server').Payload['head']) => void} fn + * @param {Payload} payload + * @param {(head_payload: Payload['head']) => void} fn * @returns {void} */ export function head(payload, fn) { @@ -162,7 +162,7 @@ export function attr(name, value, is_boolean = false) { } /** - * @param {import('#server').Payload} payload + * @param {Payload} payload * @param {boolean} is_html * @param {Record} props * @param {() => void} component @@ -309,7 +309,7 @@ export function merge_styles(attribute, styles) { * @template V * @param {Record} store_values * @param {string} store_name - * @param {import('#shared').Store | null | undefined} store + * @param {Store | null | undefined} store * @returns {V} */ export function store_get(store_values, store_name, store) { @@ -336,7 +336,7 @@ export function store_get(store_values, store_name, store) { /** * Sets the new value of a store and returns that value. * @template V - * @param {import('#shared').Store} store + * @param {Store} store * @param {V} value * @returns {V} */ @@ -350,7 +350,7 @@ export function store_set(store, value) { * @template V * @param {Record} store_values * @param {string} store_name - * @param {import('#shared').Store} store + * @param {Store} store * @param {any} expression */ export function mutate_store(store_values, store_name, store, expression) { @@ -361,7 +361,7 @@ export function mutate_store(store_values, store_name, store, expression) { /** * @param {Record} store_values * @param {string} store_name - * @param {import('#shared').Store} store + * @param {Store} store * @param {1 | -1} [d] * @returns {number} */ @@ -374,7 +374,7 @@ export function update_store(store_values, store_name, store, d = 1) { /** * @param {Record} store_values * @param {string} store_name - * @param {import('#shared').Store} store + * @param {Store} store * @param {1 | -1} [d] * @returns {number} */ @@ -412,8 +412,8 @@ export async function value_or_fallback_async(value, fallback) { } /** - * @param {import('#server').Payload} payload - * @param {void | ((payload: import('#server').Payload, props: Record) => void)} slot_fn + * @param {Payload} payload + * @param {void | ((payload: Payload, props: Record) => void)} slot_fn * @param {Record} slot_props * @param {null | (() => void)} fallback_fn * @returns {void} diff --git a/packages/svelte/src/internal/server/types.d.ts b/packages/svelte/src/internal/server/types.d.ts index d0c4a63f87..2f472c5c78 100644 --- a/packages/svelte/src/internal/server/types.d.ts +++ b/packages/svelte/src/internal/server/types.d.ts @@ -13,11 +13,9 @@ export interface Component { export interface Payload { out: string; - anchor: number; head: { title: string; out: string; - anchor: number; }; }