From c7bd87bd836715f9e234e06d4d14cc4324b2ae00 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 1 May 2018 21:24:22 -0400 Subject: [PATCH] evaluate each block key in child scope - fixes #1397 --- src/compile/nodes/EachBlock.ts | 8 +++---- .../dev-warning-missing-data-each/_config.js | 22 +++++++++++++++++++ .../dev-warning-missing-data-each/main.html | 3 +++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 test/runtime/samples/dev-warning-missing-data-each/_config.js create mode 100644 test/runtime/samples/dev-warning-missing-data-each/main.html diff --git a/src/compile/nodes/EachBlock.ts b/src/compile/nodes/EachBlock.ts index 6d771dbf87..35376c9e2b 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 = []; @@ -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 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 0000000000..a8eb59216a --- /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 0000000000..6b6a72204e --- /dev/null +++ b/test/runtime/samples/dev-warning-missing-data-each/main.html @@ -0,0 +1,3 @@ +{#each letters as letter (letter.id)} +
{letter.char}
+{/each} \ No newline at end of file