handle elseif blocks with no else

pull/1773/head
Rich Harris 6 years ago
parent cdddaa7c00
commit 4f88e43c37

@ -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;`}
}

@ -0,0 +1,21 @@
export default {
data: {
x: 11
},
html: `
<p>x is greater than 10</p>
`,
test(assert, component, target) {
component.set({ x: 4 });
assert.htmlEqual(target.innerHTML, `
<p>x is less than 5</p>
`);
component.set({ x: 6 });
assert.htmlEqual(target.innerHTML, ``);
component.destroy();
}
};

@ -0,0 +1,5 @@
{#if x > 10}
<p>x is greater than 10</p>
{:elseif x < 5}
<p>x is less than 5</p>
{/if}
Loading…
Cancel
Save