diff --git a/src/compile/nodes/EachBlock.ts b/src/compile/nodes/EachBlock.ts index 6d771dbf879f..d9c93fc03692 100644 --- a/src/compile/nodes/EachBlock.ts +++ b/src/compile/nodes/EachBlock.ts @@ -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 : []; diff --git a/test/runtime/samples/dev-warning-missing-data-each/_config.js b/test/runtime/samples/dev-warning-missing-data-each/_config.js new file mode 100644 index 000000000000..a8eb59216a48 --- /dev/null +++ b/test/runtime/samples/dev-warning-missing-data-each/_config.js @@ -0,0 +1,22 @@ +export default { + dev: true, + + data: { + letters: [ + { + id: 1, + char: 'a', + }, + { + id: 2, + char: 'b', + }, + { + id: 3, + char: 'c', + }, + ], + }, + + warnings: [], +}; diff --git a/test/runtime/samples/dev-warning-missing-data-each/main.html b/test/runtime/samples/dev-warning-missing-data-each/main.html new file mode 100644 index 000000000000..6b6a72204e0e --- /dev/null +++ b/test/runtime/samples/dev-warning-missing-data-each/main.html @@ -0,0 +1,3 @@ +{#each letters as letter (letter.id)} +