vweb/checker: show tmpl var errors

pull/5311/head
joe-conigliaro 2020-06-10 02:47:51 +10:00
parent e8e205284c
commit 3664bea912
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
5 changed files with 18 additions and 9 deletions

View File

@ -1853,6 +1853,10 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
if it.is_vweb { if it.is_vweb {
mut c2 := new_checker(c.table, c.pref) mut c2 := new_checker(c.table, c.pref)
c2.check(it.vweb_tmpl) 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 return table.void_type
} }

View File

@ -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 return
} }
g.writeln('// $' + 'method call. sym="$node.sym.name"') g.writeln('// $' + 'method call. sym="$node.sym.name"')

View File

@ -105,7 +105,7 @@ fn (mut p Parser) vweb() ast.ComptimeCall {
start_pos: 0 start_pos: 0
parent: p.global_scope 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 { if p.pref.is_verbose {
println('\n\n') println('\n\n')
println('>>> vweb template for ${path}:') println('>>> vweb template for ${path}:')
@ -117,12 +117,17 @@ fn (mut p Parser) vweb() ast.ComptimeCall {
for stmt in file.stmts { for stmt in file.stmts {
if stmt is ast.FnDecl { if stmt is ast.FnDecl {
fn_decl := stmt as ast.FnDecl fn_decl := stmt as ast.FnDecl
if fn_decl.name.starts_with('vweb_tmpl') { if fn_decl.name == 'vweb_tmpl_$p.cur_fn_name' {
body_scope := file.scope.innermost(fn_decl.body_pos.pos) tmpl_scope := file.scope.innermost(fn_decl.body_pos.pos)
for _, obj in p.scope.objects { for _, obj in p.scope.objects {
if obj is ast.Var { if obj is ast.Var {
v := obj as ast.Var mut v := obj as ast.Var
body_scope.register(v.name, *v) 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 break

View File

@ -75,12 +75,12 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
return p.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) s := scanner.new_scanner(text, .skip_comments)
mut p := Parser{ mut p := Parser{
scanner: s scanner: s
table: b_table table: b_table
pref: &pref.Preferences{} pref: pref
scope: scope scope: scope
errors: []errors.Error{} errors: []errors.Error{}
warnings: []errors.Warning{} warnings: []errors.Warning{}

View File

@ -100,7 +100,7 @@ pub fn compile_template(content, fn_name string) string {
} }
} }
s.writeln(str_end) s.writeln(str_end)
s.writeln('_tmpl_res := sb.str() ') s.writeln('tmpl_res_$fn_name := sb.str() ')
s.writeln('}') s.writeln('}')
s.writeln('// === end of vweb html template ===') s.writeln('// === end of vweb html template ===')
return s.str() return s.str()