Skip to content

Commit

Permalink
Merge pull request #1402 from sveltejs/gh-1397
Browse files Browse the repository at this point in the history
evaluate each block key in child scope
  • Loading branch information
Rich-Harris authored May 3, 2018
2 parents b64d730 + 3f012bb commit eff4319
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/compile/nodes/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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 : [];
Expand Down
22 changes: 22 additions & 0 deletions test/runtime/samples/dev-warning-missing-data-each/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default {
dev: true,

data: {
letters: [
{
id: 1,
char: 'a',
},
{
id: 2,
char: 'b',
},
{
id: 3,
char: 'c',
},
],
},

warnings: [],
};
3 changes: 3 additions & 0 deletions test/runtime/samples/dev-warning-missing-data-each/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{#each letters as letter (letter.id)}
<div>{letter.char}</div>
{/each}

0 comments on commit eff4319

Please sign in to comment.