svelte

package
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package svelte holds what compiled components need from Go beyond the JavaScript they were compiled from: Go versions of Svelte's hottest server helpers (intrinsics). Svelte's own server runtime is compiled from its source like any other module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attr added in v1.8.0

func Attr(rt *js.Realm, replacements, hasOwn, escape func() js.Value, orig js.Value) js.Value

Attr is attr from svelte/src/internal/shared/attributes.js:

export function attr(name, value, is_boolean = false) {
	if (name === 'hidden' && value !== 'until-found') {
		is_boolean = true;
	}
	if (value == null || (is_boolean && !value && value !== '')) return '';
	const normalized =
		(has_own_property.call(replacements, name) && replacements[name].get(value)) || value;
	const assignment = is_boolean ? `=""` : `="${escape_html(normalized, true)}"`;
	return ` ${name}${assignment}`;
}

replacements, hasOwn and escape read the module's bindings.

func AttrClass added in v1.8.0

func AttrClass(rt *js.Realm, toClass, escape func() js.Value, orig js.Value) js.Value

AttrClass is attr_class from svelte/src/internal/server/index.js:

export function attr_class(value, hash, directives) {
	var result = to_class(value, hash, directives);
	return result ? ` class="${escape_html(result, true)}"` : '';
}

func EnsureArrayLike added in v1.8.0

func EnsureArrayLike(rt *js.Realm, orig js.Value) js.Value

EnsureArrayLike is ensure_array_like from svelte/src/internal/server/index.js:

export function ensure_array_like(array_like_or_iterator) {
	if (array_like_or_iterator) {
		return array_like_or_iterator.length !== undefined
			? array_like_or_iterator
			: Array.from(array_like_or_iterator);
	}
	return [];
}

Arrays and strings, whose length is there without running code, come back as they are; the rest is left to the JavaScript.

func Escape

func Escape(v js.Value, s string, attr bool) js.Value

Escape escapes s, whose Value is v: when nothing needs escaping, v comes back as it is, without allocating.

func EscapeHTML

func EscapeHTML(rt *js.Realm) js.Value

EscapeHTML is escape_html from svelte/src/escaping.js, for realm rt:

const str = String(value ?? '');
… escape & and <, and " too when is_attr …

func RendererCollect added in v1.8.0

func RendererCollect(rt *js.Realm, out, collect *js.PrivateName, ctor **js.Object, orig js.Value) js.Value

RendererCollect is Renderer.prototype.#collect_content:

#collect_content(content = { head: '', body: '' }) {
	for (const item of this.#out) {
		if (typeof item === 'string') {
			content[this.type] += item;
		} else if (item instanceof Renderer) {
			item.#collect_content(content);
		}
	}
	return content;
}

ctor is the class, set after its methods are made.

func RendererPush added in v1.8.0

func RendererPush(rt *js.Realm, out *js.PrivateName, orig js.Value) js.Value

RendererPush is Renderer.prototype.push:

push(content) {
	if (typeof content === 'function') {
		this.child(async (renderer) => renderer.push(await content()));
	} else {
		this.#out.push(content);
	}
}

func Stringify added in v1.8.0

func Stringify(rt *js.Realm) js.Value

Stringify is stringify from svelte/src/internal/server/index.js:

export function stringify(value) {
	return typeof value === 'string' ? value : value == null ? '' : value + '';
}

func ToClass added in v1.8.0

func ToClass(rt *js.Realm, whitespace func() js.Value, orig js.Value) js.Value

ToClass is to_class from svelte/src/internal/shared/attributes.js.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL