var ast = parse(template);
var code = generate(ast);
- 支持属性
- 支持差值 {{}}
- 支持 mount
- 支持 更新
- new Function 报错
_c('div', [_v("\n "),_c('p', [_v("test")]),_v("\n "),_c('p', [_v("foo")]),_v("\n ")])
(function test () {
var str = `_v("\n ")`
return new Function(`return ${str}`)
})()
var code = `return 'a\\nbc'`
(new Function(code))()
var str = 'a\nbc'
var code = `return ${JSON.stringify(str)}`
(new Function(code))()
_c('div', [_v("hello {{msg}}")]) _c('div', [_v("hello "+_s(msg))])
"hello {{msg}}" "hello "+_s(msg)
var str = "hello {{msg}} foo {{bar}}";
var reg = /\{\{(\w+)\}\}/;
str.split(/(?=\{\{)|(?<=\}\})/g).map(item => {
var match = null;
if (match = item.match(reg)) {
return {
flag: true,
value: match[1]
}
} else {
return {
flag: false,
value: item
}
}
})