From 19f6abb81d8cda4a54e7a7da9c9888cad5fd2a31 Mon Sep 17 00:00:00 2001 From: paoloricciuti Date: Mon, 15 Jul 2024 16:56:24 +0200 Subject: [PATCH] fix: more precise `validate_dynamic_component` --- .changeset/gold-pumpkins-destroy.md | 5 +++++ packages/svelte/src/internal/client/validate.js | 6 +++++- .../samples/dynamic-component-func-error/A.svelte | 5 +++++ .../samples/dynamic-component-func-error/_config.js | 9 +++++++++ .../samples/dynamic-component-func-error/main.svelte | 9 +++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .changeset/gold-pumpkins-destroy.md create mode 100644 packages/svelte/tests/runtime-runes/samples/dynamic-component-func-error/A.svelte create mode 100644 packages/svelte/tests/runtime-runes/samples/dynamic-component-func-error/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/dynamic-component-func-error/main.svelte diff --git a/.changeset/gold-pumpkins-destroy.md b/.changeset/gold-pumpkins-destroy.md new file mode 100644 index 0000000000..4e9d126f0d --- /dev/null +++ b/.changeset/gold-pumpkins-destroy.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: more precise `validate_dynamic_component` diff --git a/packages/svelte/src/internal/client/validate.js b/packages/svelte/src/internal/client/validate.js index 036936f9a8..f06bc8d86f 100644 --- a/packages/svelte/src/internal/client/validate.js +++ b/packages/svelte/src/internal/client/validate.js @@ -1,6 +1,7 @@ import { untrack } from './runtime.js'; import { get_descriptor, is_array } from '../shared/utils.js'; import * as e from './errors.js'; +import { validate_component } from '../shared/validate.js'; /** regex of all html void element names */ const void_element_names = @@ -28,7 +29,10 @@ export function validate_dynamic_component(component_fn) { } catch (err) { const { message } = /** @type {Error} */ (err); - if (typeof message === 'string' && message.indexOf('is not a function') !== -1) { + if ( + typeof message === 'string' && + message.indexOf(`${validate_component.name}(...) is not a function`) !== -1 + ) { e.svelte_component_invalid_this_value(); } diff --git a/packages/svelte/tests/runtime-runes/samples/dynamic-component-func-error/A.svelte b/packages/svelte/tests/runtime-runes/samples/dynamic-component-func-error/A.svelte new file mode 100644 index 0000000000..27eaf71f9b --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/dynamic-component-func-error/A.svelte @@ -0,0 +1,5 @@ + + +{prop} diff --git a/packages/svelte/tests/runtime-runes/samples/dynamic-component-func-error/_config.js b/packages/svelte/tests/runtime-runes/samples/dynamic-component-func-error/_config.js new file mode 100644 index 0000000000..aeb12d4565 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/dynamic-component-func-error/_config.js @@ -0,0 +1,9 @@ +import { test } from '../../test'; + +export default test({ + expect_unhandled_rejections: true, + error: 'is not a function', + compileOptions: { + dev: true + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/dynamic-component-func-error/main.svelte b/packages/svelte/tests/runtime-runes/samples/dynamic-component-func-error/main.svelte new file mode 100644 index 0000000000..85edcd5afa --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/dynamic-component-func-error/main.svelte @@ -0,0 +1,9 @@ + + +{#snippet snip(comp, func)} + +{/snippet} + +{@render snip(A)}