remove isSnippet type, adjust test

pull/10800/head
Simon Holthausen 2 years ago
parent b1973f9a55
commit 9ffad5d693

@ -54,6 +54,6 @@ export function add_snippet_symbol(fn) {
* @param {any} maybeSnippet
* @returns {maybeSnippet is import('svelte').Snippet}
*/
export function isSnippet(maybeSnippet) {
export function is_snippet(maybeSnippet) {
return /** @type {any} */ (maybeSnippet)?.[snippet_symbol] === true;
}

@ -1,7 +1,7 @@
import { set, source } from '../../reactivity/sources.js';
import { get } from '../../runtime.js';
import { is_array } from '../../utils.js';
import { isSnippet } from '../blocks/snippet.js';
import { is_snippet } from '../blocks/snippet.js';
/**
* Under some circumstances, imports may be reactive in legacy mode. In that case,
@ -77,7 +77,7 @@ export function default_slot($$props) {
return children;
}
children = $$props.children;
if (isSnippet(children)) {
if (is_snippet(children)) {
return children;
}
}

@ -1,4 +1,4 @@
import { isSnippet } from './dom/blocks/snippet.js';
import { is_snippet } from './dom/blocks/snippet.js';
import { untrack } from './runtime.js';
import { is_array } from './utils.js';
@ -109,7 +109,7 @@ export function loop_guard(timeout) {
* @param {any} snippet_fn
*/
export function validate_snippet(snippet_fn) {
if (snippet_fn && !isSnippet(snippet_fn)) {
if (snippet_fn && !is_snippet(snippet_fn)) {
throw new Error(
'The argument to `{@render ...}` must be a snippet function, not a component or some other kind of function. ' +
'If you want to dynamically render one snippet or another, use `$derived` and pass its result to `{@render ...}`.'
@ -123,7 +123,7 @@ export function validate_snippet(snippet_fn) {
* @param {any} component_fn
*/
export function validate_component(component_fn) {
if (isSnippet(component_fn)) {
if (is_snippet(component_fn)) {
throw new Error('A snippet must be rendered with `{@render ...}`');
}
return component_fn;

@ -181,6 +181,5 @@ export {
hasContext,
getContext,
getAllContexts,
setContext,
isSnippet
setContext
} from '../internal/index.js';

@ -12,8 +12,7 @@ export {
tick,
unmount,
untrack,
createRoot,
isSnippet
createRoot
} from './main-client.js';
/** @returns {void} */

@ -21,14 +21,14 @@ export default function Function_prop_no_getter($$anchor, $$props) {
onmousedown: () => $.set(count, $.get(count) + 1),
onmouseup,
onmouseenter: () => $.set(count, $.proxy(plusOne($.get(count)))),
children: ($$anchor, $$slotProps) => {
children: $.add_snippet_symbol(($$anchor, $$slotProps) => {
/* Init */
var text = $.space_frag($$anchor);
/* Update */
$.text_effect(text, () => `clicks: ${$.stringify($.get(count))}`);
$.close($$anchor, text);
}
})
});
$.close_frag($$anchor, fragment);

@ -20,9 +20,9 @@ export default function Function_prop_no_getter($$payload, $$props) {
onmousedown: () => count += 1,
onmouseup,
onmouseenter: () => count = plusOne(count),
children: ($$payload, $$slotProps) => {
children: $.add_snippet_symbol(($$payload, $$slotProps) => {
$$payload.out += `clicks: ${$.escape(count)}`;
}
})
});
$$payload.out += `${anchor}`;

@ -291,12 +291,6 @@ declare module 'svelte' {
* Anything except a function
*/
type NotFunction<T> = T extends Function ? never : T;
/**
* Returns true if given parameter is a snippet.
* */
export function isSnippet(maybeSnippet: any): maybeSnippet is (this: void) => unique symbol & {
_: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
};
/**
* @deprecated Use `mount` or `hydrate` instead
*/

Loading…
Cancel
Save