From 26dfb9afa73c5fd564bbd5efbfc6155a0e9930e9 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Mon, 9 Jul 2018 13:02:17 -0400 Subject: [PATCH] in each-else, use mount/intro according to that branch's contents (#1586) Fixes # 1559 --- src/compile/nodes/EachBlock.ts | 1 + src/compile/nodes/ElseBlock.ts | 1 + .../samples/each-block-else-mount-or-intro/Widget.html | 1 + .../samples/each-block-else-mount-or-intro/_config.js | 5 +++++ .../samples/each-block-else-mount-or-intro/main.html | 9 +++++++++ 5 files changed, 17 insertions(+) create mode 100644 test/runtime/samples/each-block-else-mount-or-intro/Widget.html create mode 100644 test/runtime/samples/each-block-else-mount-or-intro/_config.js create mode 100644 test/runtime/samples/each-block-else-mount-or-intro/main.html diff --git a/src/compile/nodes/EachBlock.ts b/src/compile/nodes/EachBlock.ts index a29877367e..cae0aa7352 100644 --- a/src/compile/nodes/EachBlock.ts +++ b/src/compile/nodes/EachBlock.ts @@ -189,6 +189,7 @@ export default class EachBlock extends Node { if (this.else) { const each_block_else = compiler.getUniqueName(`${each}_else`); + const mountOrIntro = (this.else.block.hasIntroMethod || this.else.block.hasOutroMethod) ? 'i' : 'm'; block.builders.init.addLine(`var ${each_block_else} = null;`); diff --git a/src/compile/nodes/ElseBlock.ts b/src/compile/nodes/ElseBlock.ts index 742fbc7f91..7d334e3356 100644 --- a/src/compile/nodes/ElseBlock.ts +++ b/src/compile/nodes/ElseBlock.ts @@ -5,6 +5,7 @@ import mapChildren from './shared/mapChildren'; export default class ElseBlock extends Node { type: 'ElseBlock'; children: Node[]; + block: Block; constructor(compiler, parent, scope, info) { super(compiler, parent, scope, info); diff --git a/test/runtime/samples/each-block-else-mount-or-intro/Widget.html b/test/runtime/samples/each-block-else-mount-or-intro/Widget.html new file mode 100644 index 0000000000..bc56c4d894 --- /dev/null +++ b/test/runtime/samples/each-block-else-mount-or-intro/Widget.html @@ -0,0 +1 @@ +Foo diff --git a/test/runtime/samples/each-block-else-mount-or-intro/_config.js b/test/runtime/samples/each-block-else-mount-or-intro/_config.js new file mode 100644 index 0000000000..0880b896c2 --- /dev/null +++ b/test/runtime/samples/each-block-else-mount-or-intro/_config.js @@ -0,0 +1,5 @@ +export default { + nestedTransitions: true, + data: { items: [] }, + html: `No items.`, +}; diff --git a/test/runtime/samples/each-block-else-mount-or-intro/main.html b/test/runtime/samples/each-block-else-mount-or-intro/main.html new file mode 100644 index 0000000000..4604ecd788 --- /dev/null +++ b/test/runtime/samples/each-block-else-mount-or-intro/main.html @@ -0,0 +1,9 @@ +{#each items as item} + +{:else} + No items. +{/each} + +