kirbysayshi/vash

Missing output when using if/else if/else followed by another if

Closed this issue · 3 comments

The below snippet appears to be the simplest way to reproduce.

@if (true) {
<span>1</span>
} else if (false) {
<span>no</span>
} else {
<span>no</span>
}

@if (true) {
<span>2</span>
}

expected output:

<span>1</span>
<span>2</span>

actual output:

<span>1</span>

Best workaround I have is to insert an html comment before the 2nd if.

I'm noticing the same issue, but I played around with it a bit and realised that the second @if need not be prepended with an @. So, the following works for me:

@if (true) {
    <span>1</span>
} else if (false) {
    <span>no</span>
} else {
    <span>no</span>
}

if (true) {
    <span>2</span>
}

Output:

<span>1</span><span>2</span>

It IS a semantic bug, though.

To get it to output on separate lines, this is the only thing I could come up with:

@{
    if (true) {
        <span>1</span>
    } else if (false) {
        <span>no</span>
    } else {
        <span>no</span>
    }
}
@{
    if (true) {
        <span>2</span>
    }
}

Ok, this should be fixed in v0.12.4. The significant whitespace will still need a workaround (perhaps it's not an issue in the real template?), but the specific ignoring of the final if clause has been fixed. (the real issue was that the trailing block was being misplaced in the AST)

Sorry for taking so long to fix this!