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 * @param {any} maybeSnippet
* @returns {maybeSnippet is import('svelte').Snippet} * @returns {maybeSnippet is import('svelte').Snippet}
*/ */
export function isSnippet(maybeSnippet) { export function is_snippet(maybeSnippet) {
return /** @type {any} */ (maybeSnippet)?.[snippet_symbol] === true; return /** @type {any} */ (maybeSnippet)?.[snippet_symbol] === true;
} }

@ -1,7 +1,7 @@
import { set, source } from '../../reactivity/sources.js'; import { set, source } from '../../reactivity/sources.js';
import { get } from '../../runtime.js'; import { get } from '../../runtime.js';
import { is_array } from '../../utils.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, * Under some circumstances, imports may be reactive in legacy mode. In that case,
@ -77,7 +77,7 @@ export function default_slot($$props) {
return children; return children;
} }
children = $$props.children; children = $$props.children;
if (isSnippet(children)) { if (is_snippet(children)) {
return 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 { untrack } from './runtime.js';
import { is_array } from './utils.js'; import { is_array } from './utils.js';
@ -109,7 +109,7 @@ export function loop_guard(timeout) {
* @param {any} snippet_fn * @param {any} snippet_fn
*/ */
export function validate_snippet(snippet_fn) { export function validate_snippet(snippet_fn) {
if (snippet_fn && !isSnippet(snippet_fn)) { if (snippet_fn && !is_snippet(snippet_fn)) {
throw new Error( throw new Error(
'The argument to `{@render ...}` must be a snippet function, not a component or some other kind of function. ' + '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 ...}`.' '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 * @param {any} component_fn
*/ */
export function validate_component(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 ...}`'); throw new Error('A snippet must be rendered with `{@render ...}`');
} }
return component_fn; return component_fn;

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

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

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

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

@ -291,12 +291,6 @@ declare module 'svelte' {
* Anything except a function * Anything except a function
*/ */
type NotFunction<T> = T extends Function ? never : T; 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 * @deprecated Use `mount` or `hydrate` instead
*/ */

Loading…
Cancel
Save