From 31472878130a5b508f4875a6423f5e8a0709e3c9 Mon Sep 17 00:00:00 2001 From: Paolo Ricciuti Date: Fri, 25 Oct 2024 00:04:34 +0200 Subject: [PATCH] fix: prevent var name clashing for delegated events without params (#13896) --- .changeset/smooth-dragons-push.md | 5 +++++ .../compiler/phases/3-transform/client/utils.js | 2 +- .../samples/event-without-params-clash/_config.js | 14 ++++++++++++++ .../samples/event-without-params-clash/main.svelte | 6 ++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .changeset/smooth-dragons-push.md create mode 100644 packages/svelte/tests/runtime-runes/samples/event-without-params-clash/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/event-without-params-clash/main.svelte diff --git a/.changeset/smooth-dragons-push.md b/.changeset/smooth-dragons-push.md new file mode 100644 index 0000000000..6e02748b47 --- /dev/null +++ b/.changeset/smooth-dragons-push.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: prevent var name clashing for delegated events without params diff --git a/packages/svelte/src/compiler/phases/3-transform/client/utils.js b/packages/svelte/src/compiler/phases/3-transform/client/utils.js index 9463d909bc..2647f0a3be 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/utils.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/utils.js @@ -136,7 +136,7 @@ export function build_hoisted_params(node, context) { if (node.params.length === 0) { if (hoisted_params.length > 0) { // For the event object - params.push(b.id('_')); + params.push(b.id(context.state.scope.generate('_'))); } } else { for (const param of node.params) { diff --git a/packages/svelte/tests/runtime-runes/samples/event-without-params-clash/_config.js b/packages/svelte/tests/runtime-runes/samples/event-without-params-clash/_config.js new file mode 100644 index 0000000000..3dc265319d --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/event-without-params-clash/_config.js @@ -0,0 +1,14 @@ +import { flushSync } from 'svelte'; +import { test } from '../../test'; + +export default test({ + mode: ['client'], + test({ assert, target, logs }) { + const btn = target.querySelector('button'); + + flushSync(() => { + btn?.click(); + }); + assert.deepEqual(logs, ['test']); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/event-without-params-clash/main.svelte b/packages/svelte/tests/runtime-runes/samples/event-without-params-clash/main.svelte new file mode 100644 index 0000000000..eea08b3473 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/event-without-params-clash/main.svelte @@ -0,0 +1,6 @@ + + + + \ No newline at end of file