From 9e677393dcca6a98120802561645fd0397cf5d1f Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 24 Oct 2024 14:56:21 +0300 Subject: [PATCH] parser: do `import veb`, only for templates that do use functions defined in `veb` --- vlib/v/parser/tmpl.v | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vlib/v/parser/tmpl.v b/vlib/v/parser/tmpl.v index 424de90c10400c..1ea124ae304673 100644 --- a/vlib/v/parser/tmpl.v +++ b/vlib/v/parser/tmpl.v @@ -225,8 +225,7 @@ pub fn (mut p Parser) compile_template_file(template_file string, fn_name string mut source := strings.new_builder(1000) source.writeln(' import strings -import veb as _ -// === veb html template === +// === veb html template for file: ${template_file} === fn veb_tmpl_${fn_name}() string { mut sb_${fn_name} := strings.new_builder(${lstartlength})\n @@ -457,7 +456,10 @@ fn veb_tmpl_${fn_name}() string { source.writeln('}') source.writeln('// === end of veb html template_file: ${template_file} ===') - result := source.str() + mut result := source.str() + if result.contains('veb.') { + result = 'import veb\n' + result + } $if trace_tmpl_expansion ? { eprintln('>>>>>>> template expanded to:') eprintln(result)