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 ¶
- func Attr(rt *js.Realm, replacements, hasOwn, escape func() js.Value, orig js.Value) js.Value
- func AttrClass(rt *js.Realm, toClass, escape func() js.Value, orig js.Value) js.Value
- func EnsureArrayLike(rt *js.Realm, orig js.Value) js.Value
- func Escape(v js.Value, s string, attr bool) js.Value
- func EscapeHTML(rt *js.Realm) js.Value
- func RendererCollect(rt *js.Realm, out, collect *js.PrivateName, ctor **js.Object, orig js.Value) js.Value
- func RendererPush(rt *js.Realm, out *js.PrivateName, orig js.Value) js.Value
- func Stringify(rt *js.Realm) js.Value
- func ToClass(rt *js.Realm, whitespace func() js.Value, orig js.Value) js.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Attr ¶ added in v1.8.0
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
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
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 ¶
Escape escapes s, whose Value is v: when nothing needs escaping, v comes back as it is, without allocating.
func EscapeHTML ¶
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
RendererPush is Renderer.prototype.push:
push(content) {
if (typeof content === 'function') {
this.child(async (renderer) => renderer.push(await content()));
} else {
this.#out.push(content);
}
}
Types ¶
This section is empty.