diff --git a/src/compile/render-dom/wrappers/IfBlock.ts b/src/compile/render-dom/wrappers/IfBlock.ts index e45b17bcfd..284cd241de 100644 --- a/src/compile/render-dom/wrappers/IfBlock.ts +++ b/src/compile/render-dom/wrappers/IfBlock.ts @@ -221,7 +221,6 @@ export default class IfBlockWrapper extends Wrapper { ${this.branches .map(({ condition, block }) => `${condition ? `if (${condition}) ` : ''}return ${block.name};`) .join('\n')} - ${!hasElse && `return -1;`} } `); @@ -297,7 +296,7 @@ export default class IfBlockWrapper extends Wrapper { function ${select_block_type}(ctx) { ${this.branches - .map(({ condition, block }, i) => `${condition ? `if (${condition}) ` : ''}return ${block ? i : -1};`) + .map(({ condition }, i) => `${condition ? `if (${condition}) ` : ''}return ${i};`) .join('\n')} ${!hasElse && `return -1;`} } diff --git a/test/runtime/samples/if-block-elseif-no-else/_config.js b/test/runtime/samples/if-block-elseif-no-else/_config.js new file mode 100644 index 0000000000..a9b3b9c6ef --- /dev/null +++ b/test/runtime/samples/if-block-elseif-no-else/_config.js @@ -0,0 +1,21 @@ +export default { + data: { + x: 11 + }, + + html: ` +

x is greater than 10

+ `, + + test(assert, component, target) { + component.set({ x: 4 }); + assert.htmlEqual(target.innerHTML, ` +

x is less than 5

+ `); + + component.set({ x: 6 }); + assert.htmlEqual(target.innerHTML, ``); + + component.destroy(); + } +}; diff --git a/test/runtime/samples/if-block-elseif-no-else/main.html b/test/runtime/samples/if-block-elseif-no-else/main.html new file mode 100644 index 0000000000..a3bd474af7 --- /dev/null +++ b/test/runtime/samples/if-block-elseif-no-else/main.html @@ -0,0 +1,5 @@ +{#if x > 10} +

x is greater than 10

+{:elseif x < 5} +

x is less than 5

+{/if}