Merge pull request #1402 from sveltejs/gh-1397

evaluate each block key in child scope
pull/1408/head
Rich Harris 6 years ago committed by GitHub
commit eff431965e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 = [];
@ -44,6 +40,10 @@ export default class EachBlock extends Node {
this.scope.add(context.key.name, this.expression.dependencies);
});
this.key = info.key
? new Expression(compiler, this, this.scope, info.key)
: null;
if (this.index) {
// index can only change if this is a keyed each block
const dependencies = this.key ? this.expression.dependencies : [];

@ -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