kirbysayshi/vash

Most templates failing when updating from 0.7.12-1 to latest

Closed this issue · 3 comments

When I upgrade vash using npm i vash@latest, I receive an error on most of my pages with vash syntax in it.

The error message was not helpful at all:

(2500 lines)
2560 | __vbuffer.push('>');
2561 | html.vl = 193, html.vc = 6;
2562 | html.vl = 0, html.vc = 0;
2563 | html.vl = 0, html.vc = 0;
2564 | ;(__vopts && __vopts.onRenderEnd && __vopts.onRenderEnd(null, html));
2565 | return (__vopts && __vopts.asContext)
2566 | ? html
2567 | : html.toString();
2568 | } catch( e ){
2569 | html.reportError( e, html.vl, html.vc, "@{!LB!!LB!}!LB!}!LB!!LB!!LB!!LB!!LB!<script>!LB!if ( top.location !== location ) {!LB!top.location = self.location;!LB!}!LB!</script>!LB!<meta charset="utf-8"/>!LB!<meta name="msapplication-tap-highlight" content="no"/>!LB!<meta name="viewport" content="width=device-width, initial-scale=1.0"/>!LB!
(50 lines)

I tested all things, and found out that the following lines don't work anymore:

@model.list.forEach(function(item, i){
    @(item + (i === model.i.length - 1 ? '' : ', '))
})

while this one works:

@model.list.forEach(function(item, i){
    <span>
       @(item + (i === model.i.length - 1 ? '' : ', '))
    </span>
})
  1. Why?
  2. Was this on purpose, and if yes, I really can't find all these occurrences in over 50 files and fix each of them manually...

It wasn't explicitly removed, but it was something that wasn't supposed to ever actually work according to Razor. The official way of doing this is via:

@{
  <text>@('something here')</text>
}

OR

@{
  @:@('something here')
}

When I rewrote vash, I made sure variants of the syntax you're using worked. But it appears I forgot about the @() (explicit expression) case. I can add this back in, but am swamped with some other work right now... I'm not sure when I'm going to get to it. If you want to try yourself, it should be as simple as copying this code

vash/lib/parser.js

Lines 988 to 999 in e5fc332

if (
curr.type === tks.AT
&& (next.type === tks.BLOCK_KEYWORD
|| next.type === tks.BRACE_OPEN
|| next.type === tks.FUNCTION)
) {
// Backwards compatibility, allowing for @for() { @for() { @{ } } }
valueNode = this.openNode(new BlockNode(), node.values);
updateLoc(valueNode, curr);
// TODO: shouldn't this need a more accurate target (tail, values, head)?
return true;
}
but opening an expression node instead of block node as well as changing the tokens it's matching.

It would be nice if you'll do that, but for now I can live with the old version.

I implemented this in vash 0.9.4, please give it a try! Thanks for the bug report.