kirbysayshi/vash

Using braces in onclick event handler throws UnmatchedCharacterError

Closed this issue · 2 comments

The error comes from the line with the a tag, when I remove it, all works fine:

@html.extend('_layout', function(model) {
@html.block('body', function(model) {
    <!-- some <div>s -->
    @model.servers.forEach(function(server) {
        <a onclick="modal('/edit/server/@server.name')">edit</a>
    })
    <!-- some </div>s -->
})
})

The error message:

UnmatchedCharacterError: Unmatched BRACE_OPEN at line 1, character 40. Value: {
  +PROGRAM 
 | +EXPRESSION 
 | | +EXPRESSION 
 | | | [SINGLE_QUOTE (1,13): ']
 | | | [IDENTIFIER (1,14): _layout]
 | | | [SINGLE_QUOTE (1,21): ']
 | | | [CONTENT (1,22): ,]
 | | | [WHITESPACE (1,23):  ]
 | | | +BLOCK 
 | | | | [FUNCTION (1,24): function]
 | | | | [PAREN_OPEN (1,32): (]
 | | | | +BLOCK 
 | | | | | [IDENTIFIER (1,33): model]
 | | | | -BLOCK 
 | | | | [PAREN_CLOSE (1,38): )]
 | | | | [WHITESPACE (1,39):  ]
 | | | -BLOCK 
 | | -EXPRESSION 
 | -EXPRESSION 
 -PROGRAM 

I'm using v0.10.0 from NPM.

Does that exact html snippet throw the same error? I copy/pasted it into a test case and couldn't get it to through. Perhaps there is something unique in your _layout file?

var vash = require('../index');

vash.helpers.config.browser = true;
vash.install('_layout', '<html>@html.block("body")</html>')

var str = `
@html.extend('_layout', function(model) {
@html.block('body', function(model) {
    <!-- some <div>s -->
    @model.servers.forEach(function(server) {
        <a onclick="modal('/edit/server/@server.name')">edit</a>
    })
    <!-- some </div>s -->
})
})
`
var tpl2 = vash.compile(str, {useWith: false, debug: true});
var m = { servers: [{name: 'server1'}] };
console.log('FN OUTPUT', tpl2(m))

@steebchen if this is still an issue, please let me know! Otherwise going to close for now.