evaluate each block key in child scope - fixes #1397

pull/1402/head
Rich Harris 7 years ago
parent 6ec21f7a20
commit 7f58701085

@ -31,10 +31,6 @@ export default class EachBlock extends Node {
this.context = info.context.name || 'each'; // TODO this is used to facilitate binding; currently fails with destructuring
this.index = info.index;
this.key = info.key
? new Expression(compiler, this, scope, info.key)
: null;
this.scope = scope.child();
this.contexts = [];
@ -50,6 +46,10 @@ export default class EachBlock extends Node {
this.scope.add(this.index, dependencies);
}
this.key = info.key
? new Expression(compiler, this, this.scope, info.key)
: null;
this.children = mapChildren(compiler, this, this.scope, info.children);
this.else = info.else

@ -0,0 +1,22 @@
export default {
dev: true,
data: {
letters: [
{
id: 1,
char: 'a',
},
{
id: 2,
char: 'b',
},
{
id: 3,
char: 'c',
},
],
},
warnings: [],
};

@ -0,0 +1,3 @@
{#each letters as letter (letter.id)}
<div>{letter.char}</div>
{/each}
Loading…
Cancel
Save