mirror of https://github.com/sveltejs/svelte
fix: delegate functions with shadowed variables if declared locally (#16417)
parent
f343170927
commit
bdf6adb411
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: delegate functions with shadowed variables if declared locally
|
@ -0,0 +1,28 @@
|
|||||||
|
import 'svelte/internal/disclose-version';
|
||||||
|
import 'svelte/internal/flags/legacy';
|
||||||
|
import * as $ from 'svelte/internal/client';
|
||||||
|
|
||||||
|
var on_click = (e) => {
|
||||||
|
const index = Number(e.currentTarget.dataset.index);
|
||||||
|
|
||||||
|
console.log(index);
|
||||||
|
};
|
||||||
|
|
||||||
|
var root_1 = $.from_html(`<button type="button">B</button>`);
|
||||||
|
|
||||||
|
export default function Delegated_locally_declared_shadowed($$anchor) {
|
||||||
|
var fragment = $.comment();
|
||||||
|
var node = $.first_child(fragment);
|
||||||
|
|
||||||
|
$.each(node, 0, () => ({ length: 1 }), $.index, ($$anchor, $$item, index) => {
|
||||||
|
var button = root_1();
|
||||||
|
|
||||||
|
$.set_attribute(button, 'data-index', index);
|
||||||
|
button.__click = [on_click];
|
||||||
|
$.append($$anchor, button);
|
||||||
|
});
|
||||||
|
|
||||||
|
$.append($$anchor, fragment);
|
||||||
|
}
|
||||||
|
|
||||||
|
$.delegate(['click']);
|
@ -0,0 +1,13 @@
|
|||||||
|
import * as $ from 'svelte/internal/server';
|
||||||
|
|
||||||
|
export default function Delegated_locally_declared_shadowed($$payload) {
|
||||||
|
const each_array = $.ensure_array_like({ length: 1 });
|
||||||
|
|
||||||
|
$$payload.out += `<!--[-->`;
|
||||||
|
|
||||||
|
for (let index = 0, $$length = each_array.length; index < $$length; index++) {
|
||||||
|
$$payload.out += `<button type="button"${$.attr('data-index', index)}>B</button>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
$$payload.out += `<!--]-->`;
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
<script lang="ts"></script>
|
||||||
|
|
||||||
|
{#each { length: 1 }, index}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-index={index}
|
||||||
|
onclick={(e) => {
|
||||||
|
const index = Number(e.currentTarget.dataset.index)!;
|
||||||
|
console.log(index);
|
||||||
|
}}>B</button
|
||||||
|
>
|
||||||
|
{/each}
|
Loading…
Reference in new issue