mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vweb/checker: show tmpl var errors
This commit is contained in:
parent
e8e205284c
commit
3664bea912
@ -1853,6 +1853,10 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
|
||||
if it.is_vweb {
|
||||
mut c2 := new_checker(c.table, c.pref)
|
||||
c2.check(it.vweb_tmpl)
|
||||
c.warnings << c2.warnings
|
||||
c.errors << c2.errors
|
||||
c.nr_warnings += c2.nr_warnings
|
||||
c.nr_errors += c2.nr_errors
|
||||
}
|
||||
return table.void_type
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ fn (g &Gen) comptime_call(node ast.ComptimeCall) {
|
||||
}
|
||||
}
|
||||
}
|
||||
g.writeln('vweb__Context_html(&app->vweb, _tmpl_res)')
|
||||
g.writeln('vweb__Context_html(&app->vweb, tmpl_res_$g.fn_decl.name)')
|
||||
return
|
||||
}
|
||||
g.writeln('// $' + 'method call. sym="$node.sym.name"')
|
||||
|
@ -105,7 +105,7 @@ fn (mut p Parser) vweb() ast.ComptimeCall {
|
||||
start_pos: 0
|
||||
parent: p.global_scope
|
||||
}
|
||||
file := parse_text(v_code, p.table, scope, p.global_scope)
|
||||
file := parse_text(v_code, p.table, p.pref, scope, p.global_scope)
|
||||
if p.pref.is_verbose {
|
||||
println('\n\n')
|
||||
println('>>> vweb template for ${path}:')
|
||||
@ -117,12 +117,17 @@ fn (mut p Parser) vweb() ast.ComptimeCall {
|
||||
for stmt in file.stmts {
|
||||
if stmt is ast.FnDecl {
|
||||
fn_decl := stmt as ast.FnDecl
|
||||
if fn_decl.name.starts_with('vweb_tmpl') {
|
||||
body_scope := file.scope.innermost(fn_decl.body_pos.pos)
|
||||
if fn_decl.name == 'vweb_tmpl_$p.cur_fn_name' {
|
||||
tmpl_scope := file.scope.innermost(fn_decl.body_pos.pos)
|
||||
for _, obj in p.scope.objects {
|
||||
if obj is ast.Var {
|
||||
v := obj as ast.Var
|
||||
body_scope.register(v.name, *v)
|
||||
mut v := obj as ast.Var
|
||||
tmpl_scope.register(v.name, *v)
|
||||
// TODO: this is yuck, track idents in parser
|
||||
// or defer unused var logic to checker
|
||||
if v_code.contains(v.name) {
|
||||
v.is_used = true
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
|
@ -75,12 +75,12 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
|
||||
return p.stmt()
|
||||
}
|
||||
|
||||
pub fn parse_text(text string, b_table &table.Table, scope, global_scope &ast.Scope) ast.File {
|
||||
pub fn parse_text(text string, b_table &table.Table, pref &pref.Preferences, scope, global_scope &ast.Scope) ast.File {
|
||||
s := scanner.new_scanner(text, .skip_comments)
|
||||
mut p := Parser{
|
||||
scanner: s
|
||||
table: b_table
|
||||
pref: &pref.Preferences{}
|
||||
pref: pref
|
||||
scope: scope
|
||||
errors: []errors.Error{}
|
||||
warnings: []errors.Warning{}
|
||||
|
@ -100,7 +100,7 @@ pub fn compile_template(content, fn_name string) string {
|
||||
}
|
||||
}
|
||||
s.writeln(str_end)
|
||||
s.writeln('_tmpl_res := sb.str() ')
|
||||
s.writeln('tmpl_res_$fn_name := sb.str() ')
|
||||
s.writeln('}')
|
||||
s.writeln('// === end of vweb html template ===')
|
||||
return s.str()
|
||||
|
Loading…
Reference in New Issue
Block a user