Skip to content

Commit

Permalink
parser: do import veb, only for templates that do use functions def…
Browse files Browse the repository at this point in the history
…ined in `veb`
  • Loading branch information
spytheman committed Oct 24, 2024
1 parent 75de056 commit 9e67739
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions vlib/v/parser/tmpl.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9e67739

Please sign in to comment.