0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

fix binding shadow the array in each block (#1565)

This commit is contained in:
Tan Li Hau 2019-10-17 04:48:32 +08:00 committed by Conduitry
parent 36ca311500
commit 982a1937db
3 changed files with 32 additions and 1 deletions

View File

@ -495,7 +495,10 @@ export default class ElementWrapper extends Wrapper {
this.renderer.component.partly_hoisted.push(b`
function ${handler}(${arg}) {
${group.bindings.map(b => b.handler.mutation)}
${Array.from(dependencies).filter(dep => dep[0] !== '$').map(dep => b`${this.renderer.component.invalidate(dep)};`)}
${Array.from(dependencies)
.filter(dep => dep[0] !== '$')
.filter(dep => !contextual_dependencies.has(dep))
.map(dep => b`${this.renderer.component.invalidate(dep)};`)}
}
`);

View File

@ -0,0 +1,13 @@
export default {
async test({ assert, component, target }) {
assert.equal(target.querySelectorAll('input').length, 3);
const input = target.querySelector('input');
input.value = 'svelte';
await input.dispatchEvent(new window.Event('input'));
assert.equal(target.querySelectorAll('input').length, 3);
assert.deepEqual(component.data, { a: 'svelte', b: 'B', c: 'C' });
assert.deepEqual(component.x, ['a', 'b', 'c']);
},
};

View File

@ -0,0 +1,15 @@
<script>
export let x = ['a', 'b', 'c'];
export let data = {
'a': 'A',
'b': 'B',
'c': 'C',
};
export function getData() {
return data;
}
</script>
{#each x as x}
<input type=text bind:value={data[x]}>
{/each}