From df8863a08a40759815baabcaa2486f64f05070af Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Sat, 4 Nov 2023 12:54:36 +0100 Subject: [PATCH] fmt: respect raw strings in `$embed_file(r'/some/path')` expressions (#19753) --- vlib/v/fmt/fmt.v | 13 ++++++++----- vlib/v/fmt/tests/comptime_keep.vv | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 83e69315e8..4618fe6cb2 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -2066,16 +2066,19 @@ pub fn (mut f Fmt) comptime_call(node ast.ComptimeCall) { if node.method_name == 'html' { f.write('\$vweb.html()') } else { - f.write('\$tmpl(${node.args[0].expr})') + f.write('\$tmpl(') + f.expr(node.args[0].expr) + f.write(')') } } else { match true { node.is_embed { - if node.embed_file.compression_type == 'none' { - f.write('\$embed_file(${node.args[0].expr})') - } else { - f.write('\$embed_file(${node.args[0].expr}, .${node.embed_file.compression_type})') + f.write('\$embed_file(') + f.expr(node.args[0].expr) + if node.embed_file.compression_type != 'none' { + f.write(', .${node.embed_file.compression_type}') } + f.write(')') } node.is_env { f.write("\$env('${node.args_var}')") diff --git a/vlib/v/fmt/tests/comptime_keep.vv b/vlib/v/fmt/tests/comptime_keep.vv index 2952acc3c3..689cbea744 100644 --- a/vlib/v/fmt/tests/comptime_keep.vv +++ b/vlib/v/fmt/tests/comptime_keep.vv @@ -1,5 +1,7 @@ import vweb +const embedded_file = $embed_file(r'C:\Users\user\path\to\file') + struct App { a string b string