From 50ed9252de68b89810e6ff66e6843e46daf2b3c8 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Fri, 30 Mar 2018 16:10:36 -0400 Subject: [PATCH] handle empty each blocks --- src/generators/nodes/EachBlock.ts | 2 ++ test/runtime/samples/each-block-keyed-empty/_config.js | 7 +++++++ test/runtime/samples/each-block-keyed-empty/main.html | 1 + 3 files changed, 10 insertions(+) create mode 100644 test/runtime/samples/each-block-keyed-empty/_config.js create mode 100644 test/runtime/samples/each-block-keyed-empty/main.html diff --git a/src/generators/nodes/EachBlock.ts b/src/generators/nodes/EachBlock.ts index 388474bb31..41494de258 100644 --- a/src/generators/nodes/EachBlock.ts +++ b/src/generators/nodes/EachBlock.ts @@ -109,6 +109,8 @@ export default class EachBlock extends Node { parentNode: string, parentNodes: string ) { + if (this.children.length === 0) return; + const { generator } = this; const each = this.var; diff --git a/test/runtime/samples/each-block-keyed-empty/_config.js b/test/runtime/samples/each-block-keyed-empty/_config.js new file mode 100644 index 0000000000..1edbb077f9 --- /dev/null +++ b/test/runtime/samples/each-block-keyed-empty/_config.js @@ -0,0 +1,7 @@ +export default { + data: { + x: [{ z: 1 }, { z: 2 }], + }, + + html: `` +}; diff --git a/test/runtime/samples/each-block-keyed-empty/main.html b/test/runtime/samples/each-block-keyed-empty/main.html new file mode 100644 index 0000000000..f6610ae2c7 --- /dev/null +++ b/test/runtime/samples/each-block-keyed-empty/main.html @@ -0,0 +1 @@ +{{#each x as y @z}}{{/each}}