mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: preserve formatting with comments in a empty map (#13362)
This commit is contained in:
@@ -2097,7 +2097,13 @@ pub fn (mut f Fmt) map_init(node ast.MapInit) {
|
|||||||
f.mark_types_import_as_used(info.key_type)
|
f.mark_types_import_as_used(info.key_type)
|
||||||
f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
|
f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
|
||||||
}
|
}
|
||||||
f.write('{}')
|
if node.pos.line_nr == node.pos.last_line {
|
||||||
|
f.write('{}')
|
||||||
|
} else {
|
||||||
|
f.writeln('{')
|
||||||
|
f.comments(node.pre_cmnts, level: .indent)
|
||||||
|
f.write('}')
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
f.writeln('{')
|
f.writeln('{')
|
||||||
|
|||||||
11
vlib/v/fmt/tests/empty_map_fmt_keep.vv
Normal file
11
vlib/v/fmt/tests/empty_map_fmt_keep.vv
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
struct Foo {
|
||||||
|
bar map[int]int
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
foo := Foo{
|
||||||
|
bar: {
|
||||||
|
// comment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user